This commit is contained in:
naskya 2023-07-13 16:10:13 +00:00
parent 8ad603cba8
commit 22102d6c38
No known key found for this signature in database
GPG Key ID: 164DFF24E2D40139
2 changed files with 20 additions and 14 deletions

View File

@ -30,7 +30,7 @@ export const paramDef = {
export default define(meta, paramDef, async (ps, user) => { export default define(meta, paramDef, async (ps, user) => {
// Check if announcement exists // Check if announcement exists
const exist = await Announcements.findOneBy({ const exist = await Announcements.exist({
where: { id: ps.announcementId }, where: { id: ps.announcementId },
}); });
@ -39,12 +39,14 @@ export default define(meta, paramDef, async (ps, user) => {
} }
// Check if already read // Check if already read
const read = await AnnouncementReads.findOneBy({ const read = await AnnouncementReads.exist({
where: {
announcementId: ps.announcementId, announcementId: ps.announcementId,
userId: user.id, userId: user.id,
},
}); });
if (read != null) { if (read) {
return; return;
} }

View File

@ -52,14 +52,14 @@ export const paramDef = {
export default define(meta, paramDef, async (ps, me) => { export default define(meta, paramDef, async (ps, me) => {
// Fetch the list // Fetch the list
const userList = await UserLists.exist({ const listExists = await UserLists.exist({
where: { where: {
id: ps.listId, id: ps.listId,
userId: me.id, userId: me.id,
}, },
}); });
if (!exist) { if (!listExists) {
throw new ApiError(meta.errors.noSuchList); throw new ApiError(meta.errors.noSuchList);
} }
@ -72,18 +72,22 @@ export default define(meta, paramDef, async (ps, me) => {
// Check blocking // Check blocking
if (user.id !== me.id) { if (user.id !== me.id) {
const block = await Blockings.findOneBy({ const isBlocked = await Blockings.exist({
where: {
blockerId: user.id, blockerId: user.id,
blockeeId: me.id, blockeeId: me.id,
},
}); });
if (block) { if (isBlocked) {
throw new ApiError(meta.errors.youHaveBeenBlocked); throw new ApiError(meta.errors.youHaveBeenBlocked);
} }
} }
const exist = await UserListJoinings.findOneBy({ const exist = await UserListJoinings.exist({
where: {
userListId: userList.id, userListId: userList.id,
userId: user.id, userId: user.id,
},
}); });
if (exist) { if (exist) {