Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions utils/entity/foreignKey.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { databaseConfig } from "@shared/config/database.config";
import { DataSource, DataSourceOptions, EntityTarget, FindOneOptions, ObjectLiteral } from "typeorm";

export async function getDataSource(entities: DataSourceOptions['entities']) {
const dataSource = new DataSource(Object.assign(Object.assign({}, databaseConfig), { entities }));
const dataSource = new DataSource({ ...databaseConfig, entities });
await dataSource.initialize();
return dataSource;
}
Expand All @@ -18,9 +18,9 @@ export async function findOneAndAssignReferenceId(
if (keyValue && !referenceIdValue) {
const item = await dataSource.getRepository(repository)
.findOne({
where: Object.assign(Object.assign({}, where), { userId: userId })
where: { ...where, userId }
});
return item === null || item === void 0 ? void 0 : item.id;
return item?.id;
}
return referenceIdValue;
}
Expand Down Expand Up @@ -61,7 +61,7 @@ export async function findManyAndAssignReferenceIds(
if (keyValue && !referenceIdValue) {
const items = await dataSource.getRepository(repository)
.find({
where: Object.assign(Object.assign({}, where), { userId: userId })
where: { ...where, userId }
});
return items.map(item => item.id);
}
Expand Down
6 changes: 3 additions & 3 deletions utils/validation/is-unique-date-range.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { registerDecorator, ValidationOptions, ValidationArguments } from 'class-validator';
import { LessThanOrEqual, MoreThanOrEqual, Not } from "typeorm";
import { FindOptionsWhere, LessThanOrEqual, MoreThanOrEqual, Not, ObjectLiteral } from "typeorm";
import { withTemporaryDataSource } from '../entity/temporaryDataSource.util';
import { getUserIdFromUser } from '@shared/auth/auth.util';
import { getCurrentUser } from './current-user.util';
Expand All @@ -25,15 +25,15 @@ export function IsUniqueDateRange(
async validate(value: any, args: ValidationArguments) {
if (!value) return true;

const fullObject = args.object as any;
const fullObject = args.object as Record<string, any>;
const startDate = fullObject[startDateField];
const endDate = fullObject[endDateField];

if (!startDate || !endDate) return true;

const user = getCurrentUser();

const whereConditions: any = {
const whereConditions: FindOptionsWhere<ObjectLiteral> = {
[startDateField]: LessThanOrEqual(endDate),
[endDateField]: MoreThanOrEqual(startDate),
userId: fullObject.userId ?? getUserIdFromUser(user),
Expand Down
6 changes: 3 additions & 3 deletions utils/validation/max-count-by-user-limit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { registerDecorator, ValidationOptions, ValidationArguments } from 'class-validator';
import { DataSource, Not } from "typeorm";
import { DataSource, FindOptionsWhere, Not, ObjectLiteral } from "typeorm";
import { withTemporaryDataSource } from '../entity/temporaryDataSource.util';
import { getUserIdFromUser } from '@shared/auth/auth.util';
import { getCurrentUser } from './current-user.util';
Expand All @@ -19,9 +19,9 @@ export function MaxCountByUserLimit(entity: Function, getMaxLimit: GetMaxLimitTy
},
validator: {
async validate(value: any, args: ValidationArguments) {
const fullObject = args.object as any;
const fullObject = args.object as Record<string, any>;
const user = getCurrentUser();
const entityFilter: any = {
const entityFilter: FindOptionsWhere<ObjectLiteral> & { userId: number } = {
userId: fullObject.userId ?? getUserIdFromUser(user),
year: fullObject.year ?? getCurrentHebrewYear(),
};
Expand Down
Loading