ページURLが他と重複してたらエラーを投げるように (#5354)
* [Page]nameが重複したときの処理を追加 * page-editor側のerr.idにuuidを適用 * refactor * uuidをわけた
This commit is contained in:
		| @@ -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(), | ||||
|   | ||||
| @@ -4,6 +4,7 @@ import define from '../../define'; | ||||
| import { ApiError } from '../../error'; | ||||
| import { Pages, DriveFiles } from '../../../../models'; | ||||
| import { ID } from '../../../../misc/cafy-id'; | ||||
| import { Not } from 'typeorm'; | ||||
|  | ||||
| export const meta = { | ||||
| 	desc: { | ||||
| @@ -85,6 +86,11 @@ export const meta = { | ||||
| 			code: 'NO_SUCH_FILE', | ||||
| 			id: 'cfc23c7c-3887-490e-af30-0ed576703c82' | ||||
| 		}, | ||||
| 		nameAlreadyExists: { | ||||
| 			message: 'Specified name already exists.', | ||||
| 			code: 'NAME_ALREADY_EXISTS', | ||||
| 			id: '2298a392-d4a1-44c5-9ebb-ac1aeaa5a9ab' | ||||
| 		} | ||||
| 	} | ||||
| }; | ||||
|  | ||||
| @@ -109,6 +115,16 @@ export default define(meta, async (ps, user) => { | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	await Pages.find({ | ||||
| 		id: Not(ps.pageId), | ||||
| 		userId: user.id, | ||||
| 		name: ps.name | ||||
| 	}).then(result => { | ||||
| 		if (result.length > 0) { | ||||
| 			throw new ApiError(meta.errors.nameAlreadyExists); | ||||
| 		} | ||||
| 	}); | ||||
|  | ||||
| 	await Pages.update(page.id, { | ||||
| 		updatedAt: new Date(), | ||||
| 		title: ps.title, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Oni-Men
					Oni-Men