typeorm#DeepPartial TypeScript Examples
The following examples show how to use
typeorm#DeepPartial.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: notification.service.ts From office-hours with GNU General Public License v3.0 | 6 votes |
async registerDesktop(
info: DeepPartial<DesktopNotifModel>,
): Promise<DesktopNotifModel> {
// create if not exist
let dn = await DesktopNotifModel.findOne({
where: { userId: info.userId, endpoint: info.endpoint },
});
if (!dn) {
dn = await DesktopNotifModel.create(info).save();
await dn.reload();
}
return dn;
}
Example #2
Source File: time-series.mock.ts From aqualink-app with MIT License | 6 votes |
createTimeSeriesData = (
source: DeepPartial<Sources>,
): DeepPartial<TimeSeries>[] => {
const metrics = getMetrics(source.type);
return metrics
.map((metric) =>
times(10, (i) => {
const date = moment()
.subtract(i, 'days')
.set('hour', random(23))
.set('minute', random(59))
.toDate();
return {
timestamp: date,
value: getFakerValue(metric),
metric,
source,
};
}),
)
.flat();
}
Example #3
Source File: user.mock.ts From aqualink-app with MIT License | 6 votes |
adminUserMock: DeepPartial<User> = {
firebaseUid: 'abc1234',
fullName: 'John Doe',
email: '[email protected]',
organization: 'John Foundations',
location: createPoint(-113.00825255521971, 27.52775820686191),
country: 'USA',
adminLevel: AdminLevel.SuperAdmin,
description: 'A test super admin user',
imageUrl: 'http://some-sample-url.com',
}
Example #4
Source File: survey-media.mock.ts From aqualink-app with MIT License | 6 votes |
californiaSurveyTwoMedia: DeepPartial<SurveyMedia> = {
url: 'https://storage.googleapis.com/storage/reef-image-564894612112.jpg',
quality: 1,
featured: true,
hidden: false,
metadata: '{}',
observations: Observations.Healthy,
comments: 'No comments',
surveyPoint: californiaSurveyPoint,
surveyId: californiaSurveyTwo,
type: MediaType.Image,
}
Example #5
Source File: survey-media.mock.ts From aqualink-app with MIT License | 6 votes |
californiaSurveyOneMedia: DeepPartial<SurveyMedia> = {
url: 'https://storage.googleapis.com/storage/reef-image-564894612112.jpg',
quality: 1,
featured: true,
hidden: false,
metadata: '{}',
observations: Observations.Healthy,
comments: 'No comments',
surveyPoint: californiaSurveyPoint,
surveyId: californiaSurveyOne,
type: MediaType.Image,
}
Example #6
Source File: user.mock.ts From aqualink-app with MIT License | 6 votes |
siteManagerUserMock: DeepPartial<User> = {
fullName: 'John Manager',
email: '[email protected]',
organization: 'John M Foundations',
location: createPoint(-80.92402664087751, 27.605670826465445),
country: 'USA',
adminLevel: AdminLevel.SiteManager,
description: 'A test site manager user',
imageUrl: 'http://some-sample-url.com',
}
Example #7
Source File: user.mock.ts From aqualink-app with MIT License | 6 votes |
defaultUserMock: DeepPartial<User> = {
firebaseUid: 'abc1234simple',
fullName: 'John Simple',
email: '[email protected]',
organization: 'John S Foundations',
location: createPoint(23.934204963785533, 38.134556577054134),
country: 'Greece',
adminLevel: AdminLevel.Default,
description: 'A test default user',
imageUrl: 'http://some-sample-url.com',
}
Example #8
Source File: user.mock.ts From aqualink-app with MIT License | 6 votes |
testUserMock: DeepPartial<User> = {
firebaseUid: 'testTestTest',
fullName: 'Test Test',
email: '[email protected]',
organization: 'Test Foundations',
location: createPoint(23.934204963785533, 38.134556577054134),
country: 'Greece',
adminLevel: AdminLevel.Default,
description: 'A test default user',
imageUrl: 'http://some-sample-url.com',
}
Example #9
Source File: site.mock.ts From aqualink-app with MIT License | 6 votes |
athensSite: DeepPartial<Site> = {
name: 'Athens Site',
polygon: createPoint(37.57941251343841, 23.65678288302115),
depth: 15,
sensorId: 'SPOT-300434063450120',
status: SiteStatus.Shipped,
maxMonthlyMean: 25.54,
timezone: 'America/Havana',
display: true,
applied: true,
}
Example #10
Source File: site.mock.ts From aqualink-app with MIT License | 6 votes |
floridaSite: DeepPartial<Site> = {
name: 'Florida Site',
polygon: createPoint(-81.4616546356848, 25.085598897064777),
depth: 24,
status: SiteStatus.Approved,
maxMonthlyMean: 30.54,
timezone: 'America/Los_Angeles',
display: true,
applied: false,
}
Example #11
Source File: site.mock.ts From aqualink-app with MIT License | 6 votes |
californiaSite: DeepPartial<Site> = {
name: 'California Site',
sensorId: 'SPOT-0930',
polygon: createPoint(-113.79279081056211, 25.085598897064777),
depth: 43,
status: SiteStatus.Deployed,
maxMonthlyMean: 28.54,
timezone: 'America/Los_Angeles',
display: true,
applied: true,
}
Example #12
Source File: site-application.mock.ts From aqualink-app with MIT License | 6 votes |
californiaSiteApplication: DeepPartial<SiteApplication> = {
permitRequirements: 'Permit Requirements',
fundingSource: 'Funding source',
installationResources: 'Installation resources',
installationSchedule: new Date('2019-01-01'),
targetShipdate: new Date('2019-03-01'),
trackingUrl: 'https://www.tracking-service.com/bouy123',
site: californiaSite,
user: siteManagerUserMock,
}
Example #13
Source File: polymorphic.repository.ts From typeorm-polymorphic with MIT License | 6 votes |
private async deletePolymorphs(
entity: DeepPartial<E>,
options: PolymorphicMetadataInterface[],
): Promise<void | never> {
await Promise.all(
options.map(
(option: PolymorphicMetadataInterface) =>
new Promise((resolve) => {
if (!option.deleteBeforeUpdate) {
resolve(Promise.resolve());
}
const entityTypes = Array.isArray(option.classType)
? option.classType
: [option.classType];
// resolve to singular query?
resolve(
Promise.all(
entityTypes.map((type: () => Function | Function[]) => {
const repository = this.findRepository(type);
repository.delete({
[entityTypeColumn(option)]: type,
[entityIdColumn(option)]: entity[PrimaryColumn(option)],
});
}),
),
);
}),
),
);
}
Example #14
Source File: daily-data.mock.ts From aqualink-app with MIT License | 6 votes |
getMockDailyData = (
date: string,
site: DeepPartial<Site>,
): DeepPartial<DailyData> => ({
avgBottomTemperature: random(15, 35, true),
avgWaveHeight: random(10, true),
avgWindSpeed: random(10, true),
dailyAlertLevel: random(4),
degreeHeatingDays: random(70, true),
date,
site,
maxBottomTemperature: random(15, 35, true),
minBottomTemperature: random(15, 35, true),
maxWaveHeight: random(10, true),
minWaveHeight: random(10, true),
maxWindSpeed: random(10, true),
minWindSpeed: random(10, true),
satelliteTemperature: random(15, 35, true),
topTemperature: random(15, 35, true),
waveMeanDirection: random(359),
waveMeanPeriod: random(10),
weeklyAlertLevel: random(4),
windDirection: random(359),
})
Example #15
Source File: polymorphic.repository.ts From typeorm-polymorphic with MIT License | 6 votes |
create(
plainEntityLikeOrPlainEntityLikes?: DeepPartial<E> | DeepPartial<E>[],
): E | E[] {
const metadata = this.getPolymorphicMetadata();
const entity = super.create(plainEntityLikeOrPlainEntityLikes as any);
if (!metadata) {
return entity;
}
metadata.forEach((value: PolymorphicOptionsType) => {
entity[value.propertyKey] =
plainEntityLikeOrPlainEntityLikes[value.propertyKey];
});
return entity;
}
Example #16
Source File: users.spec.ts From aqualink-app with MIT License | 6 votes |
createUserDto = (mockUser: DeepPartial<User>): CreateUserDto => ({
fullName: mockUser.fullName,
email: mockUser.email as string,
organization: mockUser.organization,
country: mockUser.country,
description: mockUser.description,
imageUrl: mockUser.imageUrl,
location: mockUser.location as GeoJSON,
})
Example #17
Source File: polymorphic.repository.ts From typeorm-polymorphic with MIT License | 5 votes |
public async save<T extends DeepPartial<E>>(
entityOrEntities: T | Array<T>,
options?: SaveOptions & { reload: false },
): Promise<(T & E) | Array<T & E> | T | Array<T>> {
if (!this.isPolymorph()) {
return Array.isArray(entityOrEntities)
? super.save(entityOrEntities, options)
: super.save(entityOrEntities, options);
}
const metadata = this.getPolymorphicMetadata();
metadata.map((options: PolymorphicOptionsType) => {
if (this.isParent(options)) {
(Array.isArray(entityOrEntities)
? entityOrEntities
: [entityOrEntities]
).map((entity: E | DeepPartial<E>) => {
const parent = entity[options.propertyKey];
if (!parent || entity[entityIdColumn(options)] !== undefined) {
return entity;
}
/**
* Add parent's id and type to child's id and type field
*/
entity[entityIdColumn(options)] = parent[PrimaryColumn(options)];
entity[entityTypeColumn(options)] = parent.constructor.name;
return entity;
});
}
});
/**
* Check deleteBeforeUpdate
*/
Array.isArray(entityOrEntities)
? await Promise.all(
(entityOrEntities as Array<T>).map((entity) =>
this.deletePolymorphs(entity, metadata),
),
)
: await this.deletePolymorphs(entityOrEntities as T, metadata);
return Array.isArray(entityOrEntities)
? super.save(entityOrEntities, options)
: super.save(entityOrEntities, options);
}
Example #18
Source File: polymorphic.repository.ts From typeorm-polymorphic with MIT License | 5 votes |
save<T extends DeepPartial<E>>(
entity: T,
options?: SaveOptions & {
reload: false;
},
): Promise<T>;
Example #19
Source File: polymorphic.repository.ts From typeorm-polymorphic with MIT License | 5 votes |
save<T extends DeepPartial<E>>(
entities: T[],
options?: SaveOptions,
): Promise<(T & E)[]>;
Example #20
Source File: polymorphic.repository.ts From typeorm-polymorphic with MIT License | 5 votes |
save<T extends DeepPartial<E>>(
entities: T[],
options: SaveOptions & {
reload: false;
},
): Promise<T[]>;
Example #21
Source File: polymorphic.repository.ts From typeorm-polymorphic with MIT License | 5 votes |
create(entityLikeArray: DeepPartial<E>[]): E[];
Example #22
Source File: polymorphic.repository.ts From typeorm-polymorphic with MIT License | 5 votes |
create(entityLike: DeepPartial<E>): E;
Example #23
Source File: survey-point.mock.ts From aqualink-app with MIT License | 5 votes |
athensSurveyPointPiraeus: DeepPartial<SiteSurveyPoint> = {
imageUrl: 'http://some-sample-url.com',
name: 'Piraeus',
site: athensSite,
polygon: createPoint(23.666694170726828, 37.92090950501416),
}
Example #24
Source File: surveys.mock.ts From aqualink-app with MIT License | 5 votes |
californiaSurveyTwo: DeepPartial<Survey> = {
comments: 'California Survey Two',
diveDate: moment().subtract(2, 'days').toISOString(),
temperature: 23,
weatherConditions: WeatherConditions.Calm,
user: siteManagerUserMock,
site: californiaSite,
}
Example #25
Source File: surveys.mock.ts From aqualink-app with MIT License | 5 votes |
californiaSurveyOne: DeepPartial<Survey> = {
comments: 'California Survey One',
diveDate: moment().subtract(6, 'days').toISOString(),
temperature: 22,
weatherConditions: WeatherConditions.Calm,
user: siteManagerUserMock,
site: californiaSite,
}
Example #26
Source File: source.mock.ts From aqualink-app with MIT License | 5 votes |
athensSpotterSource: DeepPartial<Sources> = {
site: athensSite,
type: SourceType.SPOTTER,
sensorId: athensSite.sensorId,
}
Example #27
Source File: users.service.ts From aqualink-app with MIT License | 5 votes |
async create(req: Request, createUserDto: CreateUserDto): Promise<User> {
const firebaseUser = await extractAndVerifyToken(req);
if (!firebaseUser) {
throw new BadRequestException('Invalid Firebase token.');
}
if (
firebaseUser.email?.toLowerCase() !== createUserDto.email.toLowerCase()
) {
throw new BadRequestException('Invalid user email.');
}
const firebaseUid = firebaseUser.uid;
const uidExists = await this.findByFirebaseUid(firebaseUid);
if (uidExists) {
throw new BadRequestException(
`User with firebaseUid ${firebaseUid} already exists.`,
);
}
const { email } = firebaseUser;
const priorAccount = await this.findByEmail(email.toLowerCase());
if (priorAccount && priorAccount.firebaseUid) {
throw new BadRequestException(
`Email ${email} is already connected to a different firebaseUid.`,
);
}
if (priorAccount) {
const newUser = await this.migrateUserAssociations(priorAccount);
// User has associations so we have to explicitly change their admin level to site manager
if (
newUser.administeredSites.length &&
priorAccount.adminLevel !== AdminLevel.SuperAdmin
) {
// eslint-disable-next-line fp/no-mutation
priorAccount.adminLevel = AdminLevel.SiteManager;
// eslint-disable-next-line fp/no-mutation
priorAccount.administeredSites = newUser.administeredSites;
}
}
const user: DeepPartial<User> = {
...priorAccount,
...createUserDto,
adminLevel: priorAccount?.adminLevel || AdminLevel.Default,
email: email.toLowerCase(),
firebaseUid,
};
const createdUser = await this.usersRepository.save(user);
const collection = await this.collectionRepository.findOne({
where: { user: createdUser },
});
if (!collection) {
await this.collectionRepository.save(
defaultUserCollection(
createdUser.id,
priorAccount?.administeredSites.map((site) => site.id),
),
);
}
return createdUser;
}
Example #28
Source File: collection.mock.ts From aqualink-app with MIT License | 5 votes |
adminCollectionMock: DeepPartial<Collection> = {
isPublic: true,
name: 'Admin Dashboard',
sites: [floridaSite, californiaSite, athensSite],
user: adminUserMock,
}
Example #29
Source File: collection.mock.ts From aqualink-app with MIT License | 5 votes |
defaultCollectionMock: DeepPartial<Collection> = {
isPublic: false,
name: 'Default User Dashboard',
user: defaultUserMock,
}