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
15 changes: 8 additions & 7 deletions src/models/Regexp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ interface IRegexpModel<T extends RegexpDoc> extends M<T> {
// region Validators
RegexpSchema.path("name").validate({
isAsync: true,
validator: async (value, respond) => {
const result = await Model.findOne({ name: value }).exec();
return respond(!result);
validator: async function nameExistValidator(value, respond) {
return respond(await existsValidator.bind(this)(
Model, "name", value
));
},
message: "The name is exist"
});
Expand All @@ -99,13 +100,13 @@ RegexpSchema.path("value").validate({

RegexpSchema.path("value").validate({
isAsync: true,
validator: async function ValueExistValidator(value, respond) {
validator: async function valueExistValidator(value, respond) {
if (this && this.hidden) {
return respond(true);
}
const result =
await Model.findOne({ value: value, hidden: false }).exec();
return respond(!result);
return respond(await existsValidator.bind(this)(
Model, "value", value, { extraCond: { hidden: false } }
));
},
message: "The value is exist"
});
Expand Down
4 changes: 2 additions & 2 deletions src/modules/regexps/regexps.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsString, IsMongoId, IsOptional } from "class-validator";
import { IsString, IsMongoId, IsOptional, IsBoolean } from "class-validator";
import { ObjectId } from "@models/common";
import { ApiModelProperty, ApiModelPropertyOptional } from "@nestjs/swagger";

Expand Down Expand Up @@ -48,6 +48,6 @@ export class EditRegexpDot implements IRegexp {
public readonly link: ObjectId;
@ApiModelPropertyOptional({ type: Boolean })
@IsOptional()
@IsMongoId()
@IsBoolean()
public readonly hidden: boolean;
}
6 changes: 3 additions & 3 deletions test/api/regexps.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@ describe("Regexp E2E Api", () => {
status.should.be.eql(400);
});

step("Modify Exist Value", async () => {
// Ignore Self Value
xstep("Modify Exist Value", async () => {
const data = {
name: newName(),
value: "^modify.exist.value"
};
const raw = await RegexpsModel.addRegexp(data.name, data.value);
ids.regexps.push(raw._id);
const { body: result, status: status } =
await request.post(`${URL}/${raw._id}`)
const { body: result, status } = await request.post(`${URL}/${raw._id}`)
.send({ value: data.value }).then();
status.should.be.eql(400);
});
Expand Down
12 changes: 12 additions & 0 deletions test/issues/gitlab/issue_2.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,17 @@ describe("Fix Issues", () => {
body.link._id.should.be.eql(targetId);
});

step("Modify Regexp link with other fields", async () => {
const url = `/api/v1/regexps/${ids.regexps[0]}`;
const targetId = ids.categories[7].toString();

const { body } = await request.get(url).then();
body.link = targetId;

const { status, body: result } = await request.post(url)
.send(body).then();
status.should.be.not.eql(400);
});

});
});