diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index 3afd7bf6..6364a570 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -335,6 +335,47 @@ export class OrganizationController extends Controller { return error; } } + + /** + * API ตั้งเวลาเผยแพร่ + * + * @summary ORG_025 - ตั้งเวลาเผยแพร่ (ADMIN) #27 + * + * @param {string} id Id root + */ + @Put("/set/publish/{id}") + async Edit( + @Path() id: string, + @Body() requestBody: {"orgPublishDate": Date}, + @Request() request: { user: Record }, + ) { + try { + const rootIdExits = await this.orgRootRepository.findOne({ + where: { id: id }, + }); + if (!rootIdExits) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RootId"); + } + + const orgRevision = await this.orgRevisionRepository.findOne({ + where: { id: rootIdExits.orgRevisionId, orgRevisionIsDraft: true, orgRevisionIsCurrent: false } + }); + if (!orgRevision) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId"); + } + + orgRevision.lastUpdateUserId = request.user.sub; + orgRevision.lastUpdateFullName = request.user.name; + orgRevision.lastUpdatedAt = new Date(); + orgRevision.orgPublishDate = requestBody.orgPublishDate + + this.orgRevisionRepository.merge(orgRevision, requestBody); + await this.orgRevisionRepository.save(orgRevision); + return new HttpSuccess(); + } catch (error) { + return error; + } + } } function ANY(arg0: OrgRevision[]): string | import("typeorm").FindOperator | undefined { throw new Error("Function not implemented.");