diff --git a/.eslintrc.cjs b/.eslintrc.cjs index b7b3ace..3a11b8b 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -33,6 +33,7 @@ module.exports = { project: ['./tsconfig.json'], }, rules: { + 'no-implicit-coercion': 'error', 'max-classes-per-file': ['error', { ignoreExpressions: true }], '@typescript-eslint/no-floating-promises': 'error', '@typescript-eslint/no-unused-vars': [ diff --git a/spec/pgsql/pgsql.spec.ts b/spec/pgsql/pgsql.spec.ts index e828626..fbd04e0 100644 --- a/spec/pgsql/pgsql.spec.ts +++ b/spec/pgsql/pgsql.spec.ts @@ -103,9 +103,9 @@ describe('Search complex conditions', () => { expect(updateBody.id).toEqual(createBody.id); expect(updateBody.name).toBe('changed'); - const newId = +createBody.id + 1; + const newId = Number(createBody.id) + 1; const { body: upsertBody } = await request(app.getHttpServer()).put(`/base/${newId}`).send({ name: 'name2' }).expect(HttpStatus.OK); - expect(+upsertBody.id).toEqual(newId); + expect(Number(upsertBody.id)).toEqual(newId); expect(upsertBody.name).toEqual('name2'); const { body: deleteBody } = await request(app.getHttpServer()).delete(`/base/${createBody.id}`).expect(HttpStatus.OK); diff --git a/spec/relation-entities/comment-relation.interceptor.ts b/spec/relation-entities/comment-relation.interceptor.ts index 1fb2a2c..28db042 100644 --- a/spec/relation-entities/comment-relation.interceptor.ts +++ b/spec/relation-entities/comment-relation.interceptor.ts @@ -8,7 +8,7 @@ export class CommentRelationInterceptor extends CustomRequestInterceptor { async overrideOptions(req: Request): Promise { return new Promise((resolve, _reject) => { resolve({ - relations: +req.params.id % 2 === 0 ? ['writer'] : [], + relations: Number(req.params.id) % 2 === 0 ? ['writer'] : [], }); }); } diff --git a/spec/request-interceptor/delete.request.interceptor.ts b/spec/request-interceptor/delete.request.interceptor.ts index 9ecd75a..5e150cc 100644 --- a/spec/request-interceptor/delete.request.interceptor.ts +++ b/spec/request-interceptor/delete.request.interceptor.ts @@ -6,7 +6,7 @@ import { CustomRequestInterceptor, CustomDeleteRequestOptions } from '../../src' @Injectable() export class DeleteRequestInterceptor extends CustomRequestInterceptor { async overrideOptions(req: Request): Promise { - const softDeleted = +req.params.id > 2 ? undefined : false; + const softDeleted = Number(req.params.id) > 2 ? undefined : false; return new Promise((resolve, _reject) => { resolve({ diff --git a/spec/request-interceptor/read-one.request.interceptor.ts b/spec/request-interceptor/read-one.request.interceptor.ts index d03cef6..6f19cfd 100644 --- a/spec/request-interceptor/read-one.request.interceptor.ts +++ b/spec/request-interceptor/read-one.request.interceptor.ts @@ -9,7 +9,7 @@ export class ReadOneRequestInterceptor extends CustomRequestInterceptor { return new Promise((resolve, _reject) => { resolve({ fields: req.params.id === '1' ? ['name', 'createdAt'] : undefined, - softDeleted: +req.params.id % 2 === 0, + softDeleted: Number(req.params.id) % 2 === 0, }); }); } diff --git a/spec/response-interceptor/response-custom.interceptor.ts b/spec/response-interceptor/response-custom.interceptor.ts index 819e57f..dd27ee7 100644 --- a/spec/response-interceptor/response-custom.interceptor.ts +++ b/spec/response-interceptor/response-custom.interceptor.ts @@ -14,7 +14,7 @@ export class ResponseCustomInterceptor implements NestInterceptor { ? data : { ..._.omit(data, ['deletedAt', 'lastModifiedAt']), - createdAt: +data.createdAt, + createdAt: Number(data.createdAt), custom: Date.now(), }; }), diff --git a/src/lib/crud.route.factory.ts b/src/lib/crud.route.factory.ts index 239f143..33616d4 100644 --- a/src/lib/crud.route.factory.ts +++ b/src/lib/crud.route.factory.ts @@ -81,7 +81,7 @@ export class CrudRouteFactory { const entityColumns = columnList.map(({ propertyName, options }) => ({ name: propertyName, type: options.type, - isPrimary: !!options.primary, + isPrimary: Boolean(options.primary), })); this.entity.columns = entityColumns; diff --git a/src/lib/interceptor/search-request.interceptor.ts b/src/lib/interceptor/search-request.interceptor.ts index 5766f8f..2c285ae 100644 --- a/src/lib/interceptor/search-request.interceptor.ts +++ b/src/lib/interceptor/search-request.interceptor.ts @@ -232,11 +232,11 @@ export function SearchRequestInterceptor(crudOptions: CrudOptions, factoryOption if (take == null) { throw new UnprocessableEntityException('take must be positive number type'); } - const takeNumber = +take; + const takeNumber = Number(take); if (!Number.isInteger(takeNumber) || takeNumber < 1) { throw new UnprocessableEntityException('take must be positive number type'); } - if (!!limitOfTake && takeNumber > limitOfTake) { + if (limitOfTake !== undefined && takeNumber > limitOfTake) { throw new UnprocessableEntityException(`take must be less than ${limitOfTake}`); } return takeNumber;