Skip to content

Commit 3506a6f

Browse files
committed
Add uuid condition in isUnique except conditiion
1 parent 2eca74f commit 3506a6f

File tree

5 files changed

+19
-22
lines changed

5 files changed

+19
-22
lines changed

decorators/unique.decorator.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Injectable, Param, Req } from "@nestjs/common";
1+
import { Injectable } from "@nestjs/common";
22
import {
33
registerDecorator,
44
ValidationArguments,
@@ -33,11 +33,7 @@ export function isUnique(options: IsUniqueInterface, validationOptions?: Validat
3333
@Injectable()
3434
export class IsUniqueConstraint implements ValidatorConstraintInterface {
3535
constructor() {}
36-
async validate(
37-
value: any,
38-
args?: ValidationArguments,
39-
@Param("id") id?: any,
40-
): Promise<boolean> {
36+
async validate(value: any, args?: ValidationArguments): Promise<boolean> {
4137
// catch options from decorator
4238
const { tableName, column, except }: IsUniqueInterface = args?.constraints[0];
4339
const requestParams: any = args?.object;
@@ -47,7 +43,12 @@ export class IsUniqueConstraint implements ValidatorConstraintInterface {
4743
};
4844

4945
if (except) {
50-
query["_id"] = { $ne: requestParams._id };
46+
if (requestParams._id) {
47+
query["_id"] = { $ne: requestParams._id };
48+
}
49+
if (requestParams.uuid) {
50+
query["uuid"] = { $ne: requestParams.uuid };
51+
}
5152
}
5253

5354
const checkExists = await mongoose.connection.collection(tableName).findOne(query);

dist/decorators/unique.decorator.js

Lines changed: 7 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/decorators/unique.decorator.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coderomeos/nestjs-helper-library",
3-
"version": "0.1.29",
3+
"version": "0.1.30",
44
"description": "A nestjs helper library",
55
"scripts": {
66
"test": "echo \"Error: no test specified\" && exit 1",

0 commit comments

Comments
 (0)