From eebb3b21c16c5b4105970ed8d0d2b71218b06e8e Mon Sep 17 00:00:00 2001 From: Shiorin Date: Thu, 30 Sep 2021 08:23:44 +0700 Subject: [PATCH 1/2] =?UTF-8?q?[API]=20-=20=E0=B9=80=E0=B8=A1=E0=B8=B7?= =?UTF-8?q?=E0=B9=88=E0=B8=AD=20Edit=20Post=20=E0=B9=81=E0=B8=A5=E0=B9=89?= =?UTF-8?q?=E0=B8=A7=20objectiveTag/emergencyEventTag=20=E0=B8=9A=E0=B8=B1?= =?UTF-8?q?=E0=B8=99=E0=B8=97=E0=B8=B6=E0=B8=81=E0=B8=84=E0=B9=88=E0=B8=B2?= =?UTF-8?q?=E0=B9=84=E0=B8=A1=E0=B9=88=E0=B8=96=E0=B8=B9=E0=B8=81=E0=B8=95?= =?UTF-8?q?=E0=B9=89=E0=B8=AD=E0=B8=87=20(#358)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/api/controllers/PagePostController.ts | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/api-spanboon/src/api/controllers/PagePostController.ts b/api-spanboon/src/api/controllers/PagePostController.ts index 2b58aee19..fff9eff93 100644 --- a/api-spanboon/src/api/controllers/PagePostController.ts +++ b/api-spanboon/src/api/controllers/PagePostController.ts @@ -1514,19 +1514,6 @@ export class PagePostController { // find gallery update ordering const gallery: PostsGallery[] = await this.postGalleryService.find({ where: { _id: new ObjectID(data.id) } }); if (gallery.length > 0) { - // const isContain = gallery.find(object => { - // console.log('object.fileId ',object.fileId) - // console.log('data.fileId ',data.fileId) - // console.log('>>> ',new ObjectID(object.fileId) === new ObjectID(data.fileId) ? 'true' : 'false') - // return (object.fileId === new ObjectID(data.fileId)) && (object.ordering !== data.asset.ordering) - // }); - // if(isContain){ - // continue; - // } else { - // console.log('isContain ',data) - // } - // console.log(isContain); - const updateImageQuery = { _id: new ObjectID(data.id) }; const newImageValue = { $set: { @@ -1672,7 +1659,14 @@ export class PagePostController { return res.status(400).send(ResponseUtil.getErrorResponse('Objective was not found.', undefined)); } - objectiveTag = obj.hashTag; + let objHashTag = undefined; + try { + objHashTag = await this.hashTagService.findOne({ _id: obj.hashTag }); + } catch (error) { + console.log('find objective hashTag error: ', error); + } + + objectiveTag = objHashTag === undefined ? '' : objHashTag.name; } // emergencyEvent @@ -1686,7 +1680,14 @@ export class PagePostController { return res.status(400).send(ResponseUtil.getErrorResponse('Emergency Event was not found.', undefined)); } - emergencyEventTag = emerEvent.hashTag; + let emerHashTag = undefined; + try { + emerHashTag = await this.hashTagService.findOne({ _id: emerEvent.hashTag }); + } catch (error) { + console.log('find emergency hashTag error: ', error); + } + + emergencyEventTag = emerHashTag === undefined ? '' : emerHashTag.name; } // need From 0835cbeefd37453ac7cc95c953396d807ec57f1f Mon Sep 17 00:00:00 2001 From: Shiorin Date: Thu, 30 Sep 2021 08:24:21 +0700 Subject: [PATCH 2/2] clear unuse and add error type when catch --- api-spanboon/src/api/controllers/AllocateController.ts | 4 ++-- api-spanboon/src/api/controllers/EmergencyEventController.ts | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/api-spanboon/src/api/controllers/AllocateController.ts b/api-spanboon/src/api/controllers/AllocateController.ts index c7a2b188f..e24c91783 100644 --- a/api-spanboon/src/api/controllers/AllocateController.ts +++ b/api-spanboon/src/api/controllers/AllocateController.ts @@ -124,7 +124,7 @@ export class AllocateController { } else { return res.status(400).send(ResponseUtil.getErrorResponse('Cannot Calculate Allocate', undefined)); } - } catch (error) { + } catch (error: any) { return res.status(400).send(ResponseUtil.getErrorResponse('Calculate Allocate Error', error.message)); } } @@ -322,7 +322,7 @@ export class AllocateController { } else { return res.status(200).send(ResponseUtil.getSuccessResponse('Successfully Calculate Allocate', {})); } - } catch (error) { + } catch (error: any) { return res.status(400).send(ResponseUtil.getErrorResponse('Calculate Allocate Error', error.message)); } } diff --git a/api-spanboon/src/api/controllers/EmergencyEventController.ts b/api-spanboon/src/api/controllers/EmergencyEventController.ts index f16544765..0ea9ab580 100644 --- a/api-spanboon/src/api/controllers/EmergencyEventController.ts +++ b/api-spanboon/src/api/controllers/EmergencyEventController.ts @@ -12,7 +12,6 @@ import { ObjectID } from 'mongodb'; import { ObjectUtil, ResponseUtil } from '../../utils/Utils'; import { EmergencyEvent } from '../models/EmergencyEvent'; import { HashTagService } from '../services/HashTagService'; -import { HashTag } from '../models/HashTag'; import { FindHashTagRequest } from './requests/FindHashTagRequest'; import { UserFollow } from '../models/UserFollow'; import { UserEngagement } from '../models/UserEngagement'; @@ -36,7 +35,6 @@ import { EmergencyLastestProcessor } from '../processors/emergency/EmergencyLast import { EmergencyShareProcessor } from '../processors/emergency/EmergencyShareProcessor'; import { EmergencyPostLikedProcessor } from '../processors/emergency/EmergencyPostLikedProcessor'; import { DateTimeUtil } from '../../utils/DateTimeUtil'; -import { SearchFilter } from './requests/SearchFilterRequest'; @JsonController('/emergency') export class EmergencyEventController {