Skip to content

Commit

Permalink
Merge pull request #273 from Roger13579/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
y0000ga authored Jun 22, 2024
2 parents e82a4d3 + e491025 commit 342b076
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 25 deletions.
1 change: 1 addition & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ declare global {
LINEPAY_CHANNEL_SECRET_KEY: string;
LINEPAY_SITE: string;
SHARE_CODE_SECRET_KEY: string;
MOVIE_GO_URL: string;
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/controller/baseController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { CustomResponseType } from '../types/customResponseType';
import { ResponseObject } from '../utils/responseObject';

export abstract class BaseController {
/**
* @description 如果 data 裡面有 specific_redirect_url 則要轉址
*/
public formatResponse(
message: string,
status = CustomResponseType.SYSTEM_ERROR,
Expand Down
20 changes: 16 additions & 4 deletions src/controller/orderController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class OrderController extends BaseController {
);
};

/**
* @description 使用者付款後 line 會到這個 url
*/
public linePayConfirmNotify: TMethod<ILinePayConfirmReq> = async (req) => {
const linePayConfirmDto = new LinePayConfirmDTO(req);
const order =
Expand All @@ -79,13 +82,22 @@ class OrderController extends BaseController {
return this.formatResponse(
CustomResponseType.OK_MESSAGE,
CustomResponseType.OK,
order,
{
specific_redirect_url: process.env.MOVIE_GO_URL,
},
);
};

// 取消付款

// 退款
// TODO: 取消交易
public linePayCancelNotify: TMethod = async () => {
return this.formatResponse(
CustomResponseType.OK_MESSAGE,
CustomResponseType.OK,
{
specific_redirect_url: process.env.MOVIE_GO_URL,
},
);
};

public getOrders: TMethod<IGetOrdersReq> = async (req) => {
const orderFilterDto = new OrderFilterDto(req);
Expand Down
6 changes: 3 additions & 3 deletions src/dto/ticket/getTicketsDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ export class GetTicketsDto {
...(this._userId && { userId: { $eq: this._userId } }),
...(this._ids && { _id: { $in: this._ids } }),
...((this._expiredAtFrom || this._expiredAtTo) && {
startAt: {
...(this._expiredAtFrom && { $lte: this._expiredAtFrom }),
...(this._expiredAtTo && { $gte: this._expiredAtTo }),
expiredAt: {
...(this._expiredAtFrom && { $gte: this._expiredAtFrom }),
...(this._expiredAtTo && { $lte: this._expiredAtTo }),
},
}),
...(this._isPublished && { isPublished: { $eq: this._isPublished } }),
Expand Down
16 changes: 15 additions & 1 deletion src/routes/baseRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,21 @@ export abstract class BaseRoute {
(req, res, next) => {
method
.call(this.controller, req, res, next)
.then((obj) => res.status(HttpStatus.OK).json(obj))
.then((obj) => {
const isRedirect = !!(
obj.data &&
(obj.data as { specific_redirect_url?: string })
.specific_redirect_url
);
if (isRedirect) {
const { specific_redirect_url } = obj.data as {
specific_redirect_url: string;
};
res.redirect(HttpStatus.OK, specific_redirect_url);
} else {
res.status(HttpStatus.OK).json(obj);
}
})
.catch((err) => {
logger.error(err);
next(controller.formatResponse(err.message, err.status));
Expand Down
9 changes: 9 additions & 0 deletions src/routes/orderRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ export class OrderRoute extends BaseRoute {
this.responseHandler(this.controller.linePayConfirmNotify),
);

this.router.get(
'/v1/order/linePay/cancel',
/**
* #swagger.tags = ['Order']
* #swagger.summary = 'LinePay 取消交易回傳交易結果'
*/
this.responseHandler(this.controller.linePayCancelNotify),
);

// 使用者取消付款

// 使用者退款
Expand Down
17 changes: 2 additions & 15 deletions src/service/ticketService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import log4js from '../config/log4js';
import { IOrder, IOrderProduct } from '../models/order';
import { throwError } from '../utils/errorHandler';
import { CustomResponseType } from '../types/customResponseType';
import { areTimesInOrder } from '../utils/common';
import { TicketRepository } from '../repository/ticketRepository';
import { CreateTicketDto } from '../dto/ticket/createTicketDto';
import { GetTicketsDto } from '../dto/ticket/getTicketsDto';
import { SortOrder } from '../types/common.type';
import { VerifyTicketsDTO } from '../dto/ticket/verifyTicketsDto';
import { EditTicketsDTO } from '../dto/ticket/editTicketsDto';
import { CreateShareCodeDTO } from '../dto/ticket/createShareCodeDto';
Expand All @@ -32,20 +30,9 @@ export class TicketService {
private readonly productRepository: ProductRepository =
new ProductRepository();

public findTickets = async (ticketFilterDto: GetTicketsDto) => {
const { expiredAtFrom, expiredAtTo } = ticketFilterDto;
public findTickets = async (ticketFilterDto: GetTicketsDto) =>
await this.ticketRepository.findTickets(ticketFilterDto);

// 確認時間順序
areTimesInOrder(
[
{ name: 'expiredAtFrom', value: expiredAtFrom },
{ name: 'expiredAtTo', value: expiredAtTo },
],
SortOrder.asc,
);

return await this.ticketRepository.findTickets(ticketFilterDto);
};
public findSharedTickets = async (
getSharedTicketsDto: GetSharedTicketsDto,
) => {
Expand Down
4 changes: 2 additions & 2 deletions src/validator/ticket/getTicket.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import { booleanStrings } from '../../utils/constants';
export class GetTicketPipe extends PipeBase {
private validateExpiredAtFrom: TCustomValidator = (value, { req }) => {
const { expiredAtTo } = (req as IGetTicketsReq).query;
return this.validatePeriod(value, expiredAtTo, (a, b) => b.isAfter(a));
return this.validatePeriod(value, expiredAtTo, (a, b) => a.isBefore(b));
};

private validateExpiredAtTo: TCustomValidator = (value, { req }) => {
const { expiredAtFrom } = (req as IGetTicketsReq).query;
return this.validatePeriod(value, expiredAtFrom, (a, b) => a.isBefore(b));
return this.validatePeriod(expiredAtFrom, value, (a, b) => a.isBefore(b));
};

public transform = () => [
Expand Down

0 comments on commit 342b076

Please sign in to comment.