mirror of
https://iceshrimp.dev/iceshrimp/iceshrimp
synced 2024-12-27 13:08:05 +09:00
81c7db0744
* wip * wip * Update abuse-user-reports.ts * Update files.ts * Update list-remote.ts * Update list.ts * Update show-users.ts * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Update update.ts * Update search.ts * Update reactions.ts * Update search.ts * wip * wip * wip * wip * Update update.ts * Update relation.ts * Update available.ts * wip * wip * wip * Update packages/backend/src/server/api/define.ts Co-authored-by: Johann150 <johann.galle@protonmail.com> * Update define.ts * Update define.ts * typo * wip * wip * wip * wip * wip * wip * wip * wip * Update update.ts * wip * Update signup.ts * Update call.ts * minimum for limit * type * remove needless annotation * wip * Update signup.ts * wip * wip * fix * Update create.ts Co-authored-by: Johann150 <johann.galle@protonmail.com>
56 lines
1.1 KiB
TypeScript
56 lines
1.1 KiB
TypeScript
import define from '../../define';
|
|
import { ApiError } from '../../error';
|
|
import { Pages, PageLikes } from '@/models/index';
|
|
|
|
export const meta = {
|
|
tags: ['pages'],
|
|
|
|
requireCredential: true,
|
|
|
|
kind: 'write:page-likes',
|
|
|
|
errors: {
|
|
noSuchPage: {
|
|
message: 'No such page.',
|
|
code: 'NO_SUCH_PAGE',
|
|
id: 'a0d41e20-1993-40bd-890e-f6e560ae648e',
|
|
},
|
|
|
|
notLiked: {
|
|
message: 'You have not liked that page.',
|
|
code: 'NOT_LIKED',
|
|
id: 'f5e586b0-ce93-4050-b0e3-7f31af5259ee',
|
|
},
|
|
},
|
|
} as const;
|
|
|
|
const paramDef = {
|
|
type: 'object',
|
|
properties: {
|
|
pageId: { type: 'string', format: 'misskey:id' },
|
|
},
|
|
required: ['pageId'],
|
|
} as const;
|
|
|
|
// eslint-disable-next-line import/no-default-export
|
|
export default define(meta, paramDef, async (ps, user) => {
|
|
const page = await Pages.findOne(ps.pageId);
|
|
if (page == null) {
|
|
throw new ApiError(meta.errors.noSuchPage);
|
|
}
|
|
|
|
const exist = await PageLikes.findOne({
|
|
pageId: page.id,
|
|
userId: user.id,
|
|
});
|
|
|
|
if (exist == null) {
|
|
throw new ApiError(meta.errors.notLiked);
|
|
}
|
|
|
|
// Delete like
|
|
await PageLikes.delete(exist.id);
|
|
|
|
Pages.decrement({ id: page.id }, 'likedCount', 1);
|
|
});
|