Skip to content

Commit

Permalink
Merge pull request #70 from yeha98555/feature/get-check-in-page-data
Browse files Browse the repository at this point in the history
feat: Add get event info api
  • Loading branch information
yurychang committed Jun 17, 2023
2 parents 7824f57 + 5105a96 commit 2817bfc
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 540 deletions.
611 changes: 88 additions & 523 deletions mock/activities.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions mock/activity_events.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"start_at": "2023-05-20T19:30:00.000Z",
"end_at": "2023-05-20T22:30:00.000Z",
"qrcode_verify_link": "https://ticket-haven.onrender.com/admin/61577d3bbd2b96f7e225c055/scan",
"qrcode_verify_id": "https://ticket-haven.onrender.com/admin/61577d3bbd2b96f7e225c055/scan",
"created_at": "2021-10-01T00:00:00.000Z",
"updated_at": "2023-04-30T00:00:00.000Z",
"deleted_at": null
Expand Down Expand Up @@ -72,7 +72,7 @@
},
"start_at": "2023-05-21T19:30:00.000Z",
"end_at": "2023-05-21T22:30:00.000Z",
"qrcode_verify_link": "https://ticket-haven.onrender.com/admin/61577d3bbd2b96f7e225c056/scan",
"qrcode_verify_id": "https://ticket-haven.onrender.com/admin/61577d3bbd2b96f7e225c056/scan",
"created_at": "2021-10-01T00:00:00.000Z",
"updated_at": "2023-04-30T00:00:00.000Z",
"deleted_at": null
Expand Down Expand Up @@ -103,7 +103,7 @@
},
"start_at": "2023-11-11 20:00:00",
"end_at": "2023-11-11 23:00:00",
"qrcode_verify_link": "https://ticket-haven.onrender.com/admin/626b39228a8b53d25a32e760/scan",
"qrcode_verify_id": "https://ticket-haven.onrender.com/admin/626b39228a8b53d25a32e760/scan",
"created_at": "2022-12-31 08:30:00",
"updated_at": "2022-12-31 08:30:00",
"deleted_at": null
Expand Down Expand Up @@ -134,7 +134,7 @@
},
"start_at": "2023-11-10 20:00:00",
"end_at": "2023-11-10 23:00:00",
"qrcode_verify_link": "https://ticket-haven.onrender.com/admin/622a74a98a8b53d25a32e75e/scan",
"qrcode_verify_id": "https://ticket-haven.onrender.com/admin/622a74a98a8b53d25a32e75e/scan",
"created_at": "2022-12-31 08:30:00",
"updated_at": "2022-12-31 08:30:00",
"deleted_at": null
Expand Down Expand Up @@ -165,7 +165,7 @@
},
"start_at": "2023-11-11 20:00:00",
"end_at": "2023-11-11 23:00:00",
"qrcode_verify_link": "https://ticket-haven.onrender.com/admin/626b39228a8b53d25a32e762/scan",
"qrcode_verify_id": "https://ticket-haven.onrender.com/admin/626b39228a8b53d25a32e762/scan",
"created_at": "2022-12-31 08:30:00",
"updated_at": "2022-12-31 08:30:00",
"deleted_at": null
Expand All @@ -180,7 +180,7 @@
"vip": null,
"start_at": "2023-11-10 20:00:00",
"end_at": "2023-11-10 23:00:00",
"qrcode_verify_link": "https://ticket-haven.onrender.com/admin/622a74a98a8b53d25a32e76e/scan",
"qrcode_verify_id": "https://ticket-haven.onrender.com/admin/622a74a98a8b53d25a32e76e/scan",
"created_at": "2022-12-31 08:30:00",
"updated_at": "2022-12-31 08:30:00",
"deleted_at": null
Expand All @@ -195,7 +195,7 @@
"vip": null,
"start_at": "2023-11-11 20:00:00",
"end_at": "2023-11-11 23:00:00",
"qrcode_verify_link": "https://ticket-haven.onrender.com/admin/626b39228a8b53d25a32e766/scan",
"qrcode_verify_id": "https://ticket-haven.onrender.com/admin/626b39228a8b53d25a32e766/scan",
"created_at": "2022-12-31 08:30:00",
"updated_at": "2022-12-31 08:30:00",
"deleted_at": null
Expand Down
2 changes: 1 addition & 1 deletion mock/scrapy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def parse_activity(activity: Tag):
"end_at": datetime.fromisoformat(event_end),
"sell_at": datetime.fromisoformat(activity_sell_at),
"sellend_at": datetime.fromisoformat(activity_sellend_at),
"qrcode_verify_link": uuid.uuid4().hex[:24]
"qrcode_verify_id": uuid.uuid4().hex[:24]
}
events_info_list.append(event_dict)

Expand Down
7 changes: 7 additions & 0 deletions src/controllers/checkIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ const checkInController = {
const result = await checkInService.checkIn(inspectorToken, ticketToken);
res.json(Body.success(result));
}),
getEventInfo: catchAsyncError(async (req: Request, res: Response) => {
const { authId } = req.params as {
authId: string;
};
const eventInfo = await checkInService.getEventInfo(authId);
res.json(Body.success(eventInfo));
}),
};

export default checkInController;
2 changes: 1 addition & 1 deletion src/models/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const eventSchema = new Schema({
sellend_at: { type: Date, required: true },
start_at: { type: Date, required: true },
end_at: { type: Date, required: true },
qrcode_verify_link: String,
qrcode_verify_id: String,
});

const activitySchema = new Schema(
Expand Down
11 changes: 11 additions & 0 deletions src/models/vip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Schema } from 'mongoose';

const vipSchema = new Schema({
early_sell_at: { type: Date, required: true },
vip_token: [
{
token: { type: String, required: true, unique: true, sparse: true },
is_used: { type: Boolean, default: false },
},
],
});
12 changes: 11 additions & 1 deletion src/routes/checkIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ checkInRouter.post(
);

checkInRouter.get(
'/info',
'/ticket',
validateRequestQuery(
z.object({
inspectorToken: z.string(),
Expand All @@ -30,4 +30,14 @@ checkInRouter.get(
checkInController.getCheckInInfo,
);

checkInRouter.get(
'/event',
validateRequestQuery(
z.object({
authId: z.string(),
}),
),
checkInController.getEventInfo,
);

export default checkInRouter;
2 changes: 1 addition & 1 deletion src/services/activity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const activityService = {

getActivityInfo: async (id: string) => {
const activity = await ActivityModel.findById(id).select(
'-__v -create_at -update_at -deleted_at -seat_small_img_url -region -areas -events.qrcode_verify_link -events.create_at -events.update_at',
'-__v -create_at -update_at -deleted_at -seat_small_img_url -region -areas -events.qrcode_verify_id -events.create_at -events.update_at',
);
if (!activity) throw new NotFoundException();
if (!activity.is_published) throw new NotFoundException();
Expand Down
4 changes: 2 additions & 2 deletions src/services/checkIn/checkIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import TicketModel from '@/models/ticket';

const checkIn = async (inspectorToken: string, ticketToken: string) => {
const activity = await ActivityModel.findOne({})
.where('events.qrcode_verify_link')
.where('events.qrcode_verify_id')
.equals(inspectorToken);

const event = activity?.events.find(
(e) => e.qrcode_verify_link === inspectorToken,
(e) => e.qrcode_verify_id === inspectorToken,
);

if (!activity || !event) throw new NotFoundException();
Expand Down
4 changes: 2 additions & 2 deletions src/services/checkIn/generateInspectorToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ const generateInspectorToken = async (eventId: string | Types.ObjectId) => {
if (!activity || !event) throw new NotFoundException();

const linkId = uuidv4();
event.qrcode_verify_link = linkId;
event.qrcode_verify_id = linkId;

await activity.save();

return event.qrcode_verify_link;
return event.qrcode_verify_id;
};

export default generateInspectorToken;
4 changes: 2 additions & 2 deletions src/services/checkIn/getCheckInInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import UserModel from '@/models/user';

const getCheckInInfo = async (inspectorToken: string, ticketToken: string) => {
const activity = await ActivityModel.findOne({})
.where('events.qrcode_verify_link')
.where('events.qrcode_verify_id')
.equals(inspectorToken);

const event = activity?.events.find(
(e) => e.qrcode_verify_link === inspectorToken,
(e) => e.qrcode_verify_id === inspectorToken,
);

if (!activity || !event) throw new NotFoundException();
Expand Down
22 changes: 22 additions & 0 deletions src/services/checkIn/getEventInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { NotFoundException } from '@/exceptions/NotFoundException';
import ActivityModel from '@/models/activity';

export const getEventInfo = async (authId: string) => {
const activity = await ActivityModel.findOne({
'events.qrcode_verify_id': authId,
});

const event = activity?.events.find((e) => e.qrcode_verify_id === authId);

if (!activity || !event) throw new NotFoundException();

return {
activityName: activity.name,
location: activity.location,
address: activity.address,
coverImgUrl: activity.cover_img_url,
eventId: event._id,
startTime: event.start_at,
endTime: event.end_at,
};
};
2 changes: 2 additions & 0 deletions src/services/checkIn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import checkIn from './checkIn';
import generateCheckInToken from './generateCheckInToken';
import generateInspectorToken from './generateInspectorToken';
import getCheckInInfo from './getCheckInInfo';
import { getEventInfo } from './getEventInfo';

const checkInService = {
generateCheckInToken,
generateInspectorToken,
getCheckInInfo,
checkIn,
getEventInfo,
};

export default checkInService;

0 comments on commit 2817bfc

Please sign in to comment.