paricafe/packages/backend/src/server/api/endpoints/admin/emoji/add-aliases-bulk.ts
syuilo 1c67c26bd8
refactor: migrate to typeorm 3.0 (#8443)
* wip

* wip

* wip

* Update following.ts

* wip

* wip

* wip

* Update resolve-user.ts

* maxQueryExecutionTime

* wip

* wip
2022-03-26 15:34:00 +09:00

41 lines
942 B
TypeScript

import define from '../../../define.js';
import { Emojis } from '@/models/index.js';
import { In } from 'typeorm';
import { ApiError } from '../../../error.js';
import { db } from '@/db/postgre.js';
export const meta = {
tags: ['admin'],
requireCredential: true,
requireModerator: true,
} as const;
export const paramDef = {
type: 'object',
properties: {
ids: { type: 'array', items: {
type: 'string', format: 'misskey:id',
} },
aliases: { type: 'array', items: {
type: 'string',
} },
},
required: ['ids', 'aliases'],
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps) => {
const emojis = await Emojis.findBy({
id: In(ps.ids),
});
for (const emoji of emojis) {
await Emojis.update(emoji.id, {
updatedAt: new Date(),
aliases: [...new Set(emoji.aliases.concat(ps.aliases))],
});
}
await db.queryResultCache!.remove(['meta_emojis']);
});