This commit is contained in:
naskya 2023-07-13 16:10:13 +00:00
parent 98f7ebd3f7
commit 9e2443634c
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) => {
// Check if announcement exists
const exist = await Announcements.findOneBy({
const exist = await Announcements.exist({
where: { id: ps.announcementId },
});
@ -39,12 +39,14 @@ export default define(meta, paramDef, async (ps, user) => {
}
// Check if already read
const read = await AnnouncementReads.findOneBy({
announcementId: ps.announcementId,
userId: user.id,
const read = await AnnouncementReads.exist({
where: {
announcementId: ps.announcementId,
userId: user.id,
},
});
if (read != null) {
if (read) {
return;
}

View file

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