Skip to content

Commit

Permalink
Merge pull request #71 from yeha98555/69-使用票券的身份確認
Browse files Browse the repository at this point in the history
fix: User check
  • Loading branch information
yeha98555 committed Jun 18, 2023
2 parents c424482 + ec8d3ec commit 9bdb60d
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/services/checkIn/generateCheckInToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@ import TicketModel from '@/models/ticket';
import checkInToken from './checkInToken';
import { NotFoundException } from '@/exceptions/NotFoundException';
import { ConflictException } from '@/exceptions/Conflict';
import { Order } from '@/models/order';
import UserModel from '@/models/user';

const generateCheckInToken = async (userId: string, ticketNo: string) => {
const ticket = await TicketModel.findOne({
ticket_no: ticketNo,
}).populate<{ order_id: Order }>('order_id');
user_id: userId,
});

const isOwner = await UserModel.findById(ticket?.order_id.user_id);

if (!ticket || !isOwner) throw new NotFoundException();
if (!ticket) throw new NotFoundException();

if (ticket.is_used) throw new ConflictException('票卷已使用');

Expand Down

0 comments on commit 9bdb60d

Please sign in to comment.