mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
feat(api): add item validation and user ID checks in verification endpoints for UserCall, UserEmail, UserSMS, and UserWhatsApp
This commit is contained in:
@@ -136,6 +136,35 @@ export default class UserCallAPI extends BaseAPI<
|
||||
);
|
||||
}
|
||||
|
||||
const item: UserCall | null = await this.service.findOneById({
|
||||
id: req.body["itemId"],
|
||||
props: {
|
||||
isRoot: true,
|
||||
},
|
||||
select: {
|
||||
userId: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!item) {
|
||||
return Response.sendErrorResponse(
|
||||
req,
|
||||
res,
|
||||
new BadDataException("Item not found"),
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
item.userId?.toString() !==
|
||||
(req as OneUptimeRequest)?.userAuthorization?.userId?.toString()
|
||||
) {
|
||||
return Response.sendErrorResponse(
|
||||
req,
|
||||
res,
|
||||
new BadDataException("Invalid user ID"),
|
||||
);
|
||||
}
|
||||
|
||||
await this.service.resendVerificationCode(req.body.itemId);
|
||||
|
||||
return Response.sendEmptySuccessResponse(req, res);
|
||||
|
||||
@@ -137,6 +137,35 @@ export default class UserEmailAPI extends BaseAPI<
|
||||
);
|
||||
}
|
||||
|
||||
const item: UserEmail | null = await this.service.findOneById({
|
||||
id: req.body["itemId"],
|
||||
props: {
|
||||
isRoot: true,
|
||||
},
|
||||
select: {
|
||||
userId: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!item) {
|
||||
return Response.sendErrorResponse(
|
||||
req,
|
||||
res,
|
||||
new BadDataException("Item not found"),
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
item.userId?.toString() !==
|
||||
(req as OneUptimeRequest)?.userAuthorization?.userId?.toString()
|
||||
) {
|
||||
return Response.sendErrorResponse(
|
||||
req,
|
||||
res,
|
||||
new BadDataException("Invalid user ID"),
|
||||
);
|
||||
}
|
||||
|
||||
await this.service.resendVerificationCode(req.body.itemId);
|
||||
|
||||
return Response.sendEmptySuccessResponse(req, res);
|
||||
|
||||
@@ -132,6 +132,35 @@ export default class UserSMSAPI extends BaseAPI<UserSMS, UserSMSServiceType> {
|
||||
);
|
||||
}
|
||||
|
||||
const item: UserSMS | null = await this.service.findOneById({
|
||||
id: req.body["itemId"],
|
||||
props: {
|
||||
isRoot: true,
|
||||
},
|
||||
select: {
|
||||
userId: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!item) {
|
||||
return Response.sendErrorResponse(
|
||||
req,
|
||||
res,
|
||||
new BadDataException("Item not found"),
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
item.userId?.toString() !==
|
||||
(req as OneUptimeRequest)?.userAuthorization?.userId?.toString()
|
||||
) {
|
||||
return Response.sendErrorResponse(
|
||||
req,
|
||||
res,
|
||||
new BadDataException("Invalid user ID"),
|
||||
);
|
||||
}
|
||||
|
||||
await this.service.resendVerificationCode(req.body.itemId);
|
||||
|
||||
return Response.sendEmptySuccessResponse(req, res);
|
||||
|
||||
@@ -143,6 +143,35 @@ export default class UserWhatsAppAPI extends BaseAPI<
|
||||
);
|
||||
}
|
||||
|
||||
const item: UserWhatsApp | null = await this.service.findOneById({
|
||||
id: req.body["itemId"],
|
||||
props: {
|
||||
isRoot: true,
|
||||
},
|
||||
select: {
|
||||
userId: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!item) {
|
||||
return Response.sendErrorResponse(
|
||||
req,
|
||||
res,
|
||||
new BadDataException("Item not found"),
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
item.userId?.toString() !==
|
||||
(req as OneUptimeRequest)?.userAuthorization?.userId?.toString()
|
||||
) {
|
||||
return Response.sendErrorResponse(
|
||||
req,
|
||||
res,
|
||||
new BadDataException("Invalid user ID"),
|
||||
);
|
||||
}
|
||||
|
||||
await this.service.resendVerificationCode(req.body.itemId);
|
||||
|
||||
return Response.sendEmptySuccessResponse(req, res);
|
||||
|
||||
Reference in New Issue
Block a user