From 7a368bab7b3f93130fb8a2ed5e59ed5b53768762 Mon Sep 17 00:00:00 2001 From: RogerLi Date: Thu, 27 Jun 2024 00:02:41 +0800 Subject: [PATCH] feat: add get order time parameter --- src/dto/order/orderFilterDto.ts | 14 ++++++++++---- src/routes/orderRoute.ts | 8 ++++---- src/swagger/definition/order/custom.ts | 3 +++ src/validator/order/getOrder.pipe.ts | 14 ++++++++++---- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/dto/order/orderFilterDto.ts b/src/dto/order/orderFilterDto.ts index ed6c99f..47bb75a 100644 --- a/src/dto/order/orderFilterDto.ts +++ b/src/dto/order/orderFilterDto.ts @@ -120,11 +120,17 @@ export class OrderFilterDto { this._emails = emails?.split(','); this._phones = phones?.split(','); - this._createdAtTo = createdAtTo ? moment(createdAtTo).toDate() : undefined; + this._createdAtTo = createdAtTo + ? moment(createdAtTo).hour(23).minute(59).second(59).toDate() + : undefined; this._createdAtFrom = createdAtFrom - ? moment(createdAtFrom).toDate() + ? moment(createdAtFrom).hour(0).minute(0).second(0).toDate() + : undefined; + this._paidAtFrom = paidAtFrom + ? moment(paidAtFrom).hour(0).minute(0).second(0).toDate() + : undefined; + this._paidAtTo = paidAtTo + ? moment(paidAtTo).hour(23).minute(59).second(59).toDate() : undefined; - this._paidAtFrom = paidAtFrom ? moment(paidAtFrom).toDate() : undefined; - this._paidAtTo = paidAtTo ? moment(paidAtTo).toDate() : undefined; } } diff --git a/src/routes/orderRoute.ts b/src/routes/orderRoute.ts index df3de11..69240b2 100644 --- a/src/routes/orderRoute.ts +++ b/src/routes/orderRoute.ts @@ -172,7 +172,7 @@ export class OrderRoute extends BaseRoute { description: '訂單成立時間-起', type: 'string', schema:{ - $ref: "#/definitions/CustomTimeAtFromQuery" + $ref: "#/definitions/CustomGetOrderDateQuery" } } #swagger.parameters['createdAtTo'] = { @@ -181,7 +181,7 @@ export class OrderRoute extends BaseRoute { description: '訂單成立時間-迄', type: 'string', schema:{ - $ref: "#/definitions/CustomTimeAtToQuery" + $ref: "#/definitions/CustomGetOrderDateQuery" } } #swagger.parameters['paidAtFrom'] = { @@ -190,7 +190,7 @@ export class OrderRoute extends BaseRoute { description: '付款時間-起', type: 'string', schema:{ - $ref: "#/definitions/CustomTimeAtFromQuery" + $ref: "#/definitions/CustomGetOrderDateQuery" } } #swagger.parameters['paidAtTo'] = { @@ -199,7 +199,7 @@ export class OrderRoute extends BaseRoute { description: '付款時間-迄', type: 'string', schema:{ - $ref: "#/definitions/CustomTimeAtToQuery" + $ref: "#/definitions/CustomGetOrderDateQuery" } } #swagger.parameters['sortField'] = { diff --git a/src/swagger/definition/order/custom.ts b/src/swagger/definition/order/custom.ts index 6391382..f785334 100644 --- a/src/swagger/definition/order/custom.ts +++ b/src/swagger/definition/order/custom.ts @@ -18,6 +18,9 @@ export const CustomGetOrderEmailQuery = { export const CustomGetOrderPhoneQuery = { example: '0912345678', }; +export const CustomGetOrderDateQuery = { + example: '2024-06-25', +}; const propName = { userId: '使用者id', diff --git a/src/validator/order/getOrder.pipe.ts b/src/validator/order/getOrder.pipe.ts index 7ca7320..dd22e9c 100644 --- a/src/validator/order/getOrder.pipe.ts +++ b/src/validator/order/getOrder.pipe.ts @@ -14,22 +14,28 @@ import { SortOrder } from '../../types/common.type'; export class GetOrderPipe extends PipeBase { private validateCreatedAtFrom: TCustomValidator = (value, { req }) => { const { createdAtTo } = (req as IGetOrdersReq).query; - return this.validatePeriod(value, createdAtTo, (a, b) => b.isAfter(a)); + return this.validatePeriod(value, createdAtTo, (a, b) => + b.isSameOrAfter(a), + ); }; private validateCreatedAtTo: TCustomValidator = (value, { req }) => { const { createdAtFrom } = (req as IGetOrdersReq).query; - return this.validatePeriod(value, createdAtFrom, (a, b) => b.isBefore(a)); + return this.validatePeriod(value, createdAtFrom, (a, b) => + b.isSameOrBefore(a), + ); }; private validatePaidAtFrom: TCustomValidator = (value, { req }) => { const { paidAtTo } = (req as IGetOrdersReq).query; - return this.validatePeriod(value, paidAtTo, (a, b) => b.isAfter(a)); + return this.validatePeriod(value, paidAtTo, (a, b) => b.isSameOrAfter(a)); }; private validatePaidAtTo: TCustomValidator = (value, { req }) => { const { paidAtFrom } = (req as IGetOrdersReq).query; - return this.validatePeriod(value, paidAtFrom, (a, b) => b.isBefore(a)); + return this.validatePeriod(value, paidAtFrom, (a, b) => + b.isSameOrBefore(a), + ); }; public transform = () => [