ページURLが他と重複してたらエラーを投げるように (#5354)

* [Page]nameが重複したときの処理を追加

* page-editor側のerr.idにuuidを適用

* refactor

* uuidをわけた
This commit is contained in:
Oni-Men
2019-08-28 08:00:05 +09:00
committed by syuilo
parent 85721065fd
commit 2d6d9f30e1
5 changed files with 63 additions and 23 deletions

View File

@ -76,6 +76,11 @@ export const meta = {
code: 'NO_SUCH_FILE',
id: 'b7b97489-0f66-4b12-a5ff-b21bd63f6e1c'
},
nameAlreadyExists: {
message: 'Specified name already exists.',
code: 'NAME_ALREADY_EXISTS',
id: '4650348e-301c-499a-83c9-6aa988c66bc1'
}
}
};
@ -92,6 +97,15 @@ export default define(meta, async (ps, user) => {
}
}
await Pages.find({
userId: user.id,
name: ps.name
}).then(result => {
if (result.length > 0) {
throw new ApiError(meta.errors.nameAlreadyExists);
}
});
const page = await Pages.save(new Page({
id: genId(),
createdAt: new Date(),