1
1
import { Inject , Injectable } from '@nestjs/common' ;
2
- import { DataSource } from 'typeorm' ;
2
+ import { DataSource , IsNull } from 'typeorm' ;
3
3
import { Endpoint } from '@/server/api/endpoint-base.js' ;
4
4
import type { EmojisRepository } from '@/models/index.js' ;
5
5
import { DI } from '@/di-symbols.js' ;
@@ -19,9 +19,9 @@ export const meta = {
19
19
code : 'NO_SUCH_EMOJI' ,
20
20
id : '684dec9d-a8c2-4364-9aa8-456c49cb1dc8' ,
21
21
} ,
22
- alreadyexistsemoji : {
23
- message : 'Emoji already exists' ,
24
- code : 'EMOJI_ALREADY_EXISTS ' ,
22
+ sameNameEmojiExists : {
23
+ message : 'Emoji that have same name already exists. ' ,
24
+ code : 'SAME_NAME_EMOJI_EXISTS ' ,
25
25
id : '7180fe9d-1ee3-bff9-647d-fe9896d2ffb8' ,
26
26
} ,
27
27
} ,
@@ -62,9 +62,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
62
62
) {
63
63
super ( meta , paramDef , async ( ps , me ) => {
64
64
const emoji = await this . emojisRepository . findOneBy ( { id : ps . id } ) ;
65
- const emojiname = await this . emojisRepository . findOneBy ( { name : ps . name } ) ;
65
+ const sameNameEmoji = await this . emojisRepository . findOneBy ( { name : ps . name , host : IsNull ( ) } ) ;
66
66
if ( emoji == null ) throw new ApiError ( meta . errors . noSuchEmoji ) ;
67
- if ( emojiname != null && emojiname . id !== ps . id ) throw new ApiError ( meta . errors . alreadyexistsemoji ) ;
67
+ if ( sameNameEmoji != null && sameNameEmoji . id !== ps . id ) throw new ApiError ( meta . errors . sameNameEmojiExists ) ;
68
68
await this . emojisRepository . update ( emoji . id , {
69
69
updatedAt : new Date ( ) ,
70
70
name : ps . name ,
0 commit comments