From 71ed3620b177de17d8455ddbff510afe943b8330 Mon Sep 17 00:00:00 2001 From: vec Date: Thu, 21 Dec 2023 00:47:31 +0800 Subject: [PATCH] [fix] admin create photo should allow empty string desc field --- server/app/controller/admin/photo.js | 2 +- server/app/model/photo.js | 5 ++++- server/test/admin-photo.test.js | 10 ++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/server/app/controller/admin/photo.js b/server/app/controller/admin/photo.js index a0f343a..42d9a82 100644 --- a/server/app/controller/admin/photo.js +++ b/server/app/controller/admin/photo.js @@ -7,7 +7,7 @@ module.exports = app => { ctx.validate({ member_id: { type: 'integer', required: true }, gallery_id: { type: 'integer', required: true }, - desc: { type: 'string', required: true }, + desc: { type: 'string', required: true, allowEmpty: true }, src: { type: 'string', required: true }, }, data); diff --git a/server/app/model/photo.js b/server/app/model/photo.js index 10a7b0c..e7152c6 100644 --- a/server/app/model/photo.js +++ b/server/app/model/photo.js @@ -6,7 +6,10 @@ module.exports = app => { const { INTEGER, VIRTUAL, STRING, TEXT } = app.Sequelize; const Photo = app.model.define('photo', { - desc: TEXT, + desc: { + type: TEXT, + allowNull: false, + }, src: { type: STRING(2048), diff --git a/server/test/admin-photo.test.js b/server/test/admin-photo.test.js index b222483..61d3ab5 100644 --- a/server/test/admin-photo.test.js +++ b/server/test/admin-photo.test.js @@ -30,6 +30,16 @@ describe('controller/admin/photo', () => { }) }) + it('should successfully create a photo with empty string desc', async () => { + const member = await createMember(token, app, { qq_num: 22222 }) + const gallery = await commonCreateGallery(token, app, {}) + await createPhoto(token, app, { + gallery_id: gallery.id, + member_id: member.id, + desc: '', + }) + }) + it('should successfully get a photo infomation', async () => { let globalQqNum = 8000 async function createRandomPhoto() {