diff --git a/src/controllers/00-doc-template-controller.ts b/src/controllers/00-doc-template-controller.ts index b7d1a03..32822f4 100644 --- a/src/controllers/00-doc-template-controller.ts +++ b/src/controllers/00-doc-template-controller.ts @@ -8,6 +8,7 @@ import { notFoundError } from "../utils/error"; import HttpError from "../interfaces/http-error"; import HttpStatus from "../interfaces/http-status"; import { getFileBuffer, listFile } from "../utils/minio"; +import { dateFormat } from "../utils/datetime"; const quotationData = (id: string) => prisma.quotation.findFirst({ @@ -128,6 +129,23 @@ export class DocTemplateController extends Controller { template, data: record, additionalJsContext: { + date: (date: string, locale?: string) => dateFormat({ date, locale }), + dateTime: (date: string, locale?: string) => dateFormat({ date, withTime: true, locale }), + dateLong: (date: string, locale?: string) => + dateFormat({ date, locale, monthStyle: "long" }), + dateLongTime: (date: string, locale?: string) => + dateFormat({ date, withTime: true, locale, monthStyle: "long" }), + dateTH: (date: string) => dateFormat({ date, locale: "th-TH" }), + dateTimeTH: (date: string) => dateFormat({ date, withTime: true, locale: "th-TH" }), + dateLongTH: (date: string) => dateFormat({ date, locale: "th-TH", monthStyle: "long" }), + dateTimeLongTH: (date: string) => + dateFormat({ date, withTime: true, locale: "th-TH", monthStyle: "long" }), + dateEN: (date: string) => dateFormat({ date, locale: "en-US" }), + dateTimeEN: (date: string) => + dateFormat({ date, withTime: true, locale: "en-US", monthStyle: "long" }), + dateLongEN: (date: string) => dateFormat({ date, locale: "en-US" }), + dateTimeLongEN: (date: string) => + dateFormat({ date, withTime: true, locale: "en-US", monthStyle: "long" }), addressFull, addressFullTH: (addr: FullAddress) => addressFull(addr, "th"), addressFullEN: (addr: FullAddress) => addressFull(addr, "en"),