Skip to content

Commit

Permalink
Merge pull request #303 from Roger13579/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Roger13579 authored Jun 26, 2024
2 parents f931bff + 19edc24 commit d35b625
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
14 changes: 10 additions & 4 deletions src/dto/order/orderFilterDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
8 changes: 4 additions & 4 deletions src/routes/orderRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export class OrderRoute extends BaseRoute {
description: '訂單成立時間-起',
type: 'string',
schema:{
$ref: "#/definitions/CustomTimeAtFromQuery"
$ref: "#/definitions/CustomGetOrderDateQuery"
}
}
#swagger.parameters['createdAtTo'] = {
Expand All @@ -181,7 +181,7 @@ export class OrderRoute extends BaseRoute {
description: '訂單成立時間-迄',
type: 'string',
schema:{
$ref: "#/definitions/CustomTimeAtToQuery"
$ref: "#/definitions/CustomGetOrderDateQuery"
}
}
#swagger.parameters['paidAtFrom'] = {
Expand All @@ -190,7 +190,7 @@ export class OrderRoute extends BaseRoute {
description: '付款時間-起',
type: 'string',
schema:{
$ref: "#/definitions/CustomTimeAtFromQuery"
$ref: "#/definitions/CustomGetOrderDateQuery"
}
}
#swagger.parameters['paidAtTo'] = {
Expand All @@ -199,7 +199,7 @@ export class OrderRoute extends BaseRoute {
description: '付款時間-迄',
type: 'string',
schema:{
$ref: "#/definitions/CustomTimeAtToQuery"
$ref: "#/definitions/CustomGetOrderDateQuery"
}
}
#swagger.parameters['sortField'] = {
Expand Down
3 changes: 3 additions & 0 deletions src/swagger/definition/order/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export const CustomGetOrderEmailQuery = {
export const CustomGetOrderPhoneQuery = {
example: '0912345678',
};
export const CustomGetOrderDateQuery = {
example: '2024-06-25',
};

const propName = {
userId: '使用者id',
Expand Down
14 changes: 10 additions & 4 deletions src/validator/order/getOrder.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => [
Expand Down

0 comments on commit d35b625

Please sign in to comment.