draftからrequestに
Signed-off-by: mattyatea <mattyacocacora0@gmail.com>
This commit is contained in:
parent
53d250dddf
commit
8fd5eb7010
30 changed files with 184 additions and 198 deletions
|
|
@ -61,14 +61,14 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
const isDuplicate = await this.customEmojiService.checkDuplicate(ps.name);
|
||||
const isDraftDuplicate = await this.customEmojiService.checkDraftDuplicate(ps.name);
|
||||
const isRequestDuplicate = await this.customEmojiService.checkRequestDuplicate(ps.name);
|
||||
|
||||
if (isDuplicate || isDraftDuplicate) throw new ApiError(meta.errors.duplicateName);
|
||||
if (isDuplicate || isRequestDuplicate) throw new ApiError(meta.errors.duplicateName);
|
||||
const driveFile = await this.driveFilesRepository.findOneBy({ id: ps.fileId });
|
||||
|
||||
if (driveFile == null) throw new ApiError(meta.errors.noSuchFile);
|
||||
|
||||
const emoji = await this.customEmojiService.draft({
|
||||
const emoji = await this.customEmojiService.Request({
|
||||
driveFile,
|
||||
name: ps.name,
|
||||
category: ps.category ?? null,
|
||||
|
|
@ -37,12 +37,12 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
const emoji = await this.customEmojiService.getEmojiById(ps.id);
|
||||
const draftEmoji = await this.customEmojiService.getEmojiDraftById(ps.id);
|
||||
const RequestEmoji = await this.customEmojiService.getEmojiRequestById(ps.id);
|
||||
if (emoji != null) {
|
||||
await this.customEmojiService.delete(ps.id, me);
|
||||
}
|
||||
if (draftEmoji != null) {
|
||||
await this.customEmojiService.draftDelete(ps.id);
|
||||
if (RequestEmoji != null) {
|
||||
await this.customEmojiService.RequestDelete(ps.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@
|
|||
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import type { EmojiDraftsRepository } from '@/models/_.js';
|
||||
import type { MiEmojiDraft } from '@/models/EmojiDraft.js';
|
||||
import type { EmojiRequestsRepository } from '@/models/_.js';
|
||||
import type { MiEmojiRequest } from '@/models/EmojiRequest.js';
|
||||
import { QueryService } from '@/core/QueryService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { EmojiDraftsEntityService } from '@/core/entities/EmojiDraftsEntityService.js';
|
||||
import { EmojiRequestsEntityService } from '@/core/entities/EmojiRequestsEntityService.js';
|
||||
//import { sqlLikeEscape } from '@/misc/sql-like-escape.js';
|
||||
|
||||
export const meta = {
|
||||
|
|
@ -69,16 +69,16 @@ export const paramDef = {
|
|||
@Injectable()
|
||||
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
||||
constructor(
|
||||
@Inject(DI.emojiDraftsRepository)
|
||||
private emojiDraftsRepository: EmojiDraftsRepository,
|
||||
@Inject(DI.emojiRequestsRepository)
|
||||
private emojiRequestsRepository: EmojiRequestsRepository,
|
||||
|
||||
private emojiDraftsEntityService: EmojiDraftsEntityService,
|
||||
private emojiRequestsEntityService: EmojiRequestsEntityService,
|
||||
private queryService: QueryService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
const q = this.queryService.makePaginationQuery(this.emojiDraftsRepository.createQueryBuilder('emoji'), ps.sinceId, ps.untilId);
|
||||
const q = this.queryService.makePaginationQuery(this.emojiRequestsRepository.createQueryBuilder('emoji'), ps.sinceId, ps.untilId);
|
||||
|
||||
let emojis: MiEmojiDraft[];
|
||||
let emojis: MiEmojiRequest[];
|
||||
|
||||
if (ps.query) {
|
||||
//q.andWhere('emoji.name ILIKE :q', { q: `%${ sqlLikeEscape(ps.query) }%` });
|
||||
|
|
@ -102,7 +102,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
emojis = await q.limit(ps.limit).getMany();
|
||||
}
|
||||
|
||||
return this.emojiDraftsEntityService.packDetailedMany(emojis);
|
||||
return this.emojiRequestsEntityService.packDetailedMany(emojis);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -56,7 +56,7 @@ export const paramDef = {
|
|||
roleIdsThatCanBeUsedThisEmojiAsReaction: { type: 'array', items: {
|
||||
type: 'string',
|
||||
} },
|
||||
draft: { type: 'boolean' },
|
||||
Request: { type: 'boolean' },
|
||||
},
|
||||
required: ['id', 'name', 'aliases'],
|
||||
} as const;
|
||||
|
|
@ -72,22 +72,22 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
let driveFile;
|
||||
const isDraft = !!ps.draft;
|
||||
const isRequest = !!ps.Request;
|
||||
if (ps.fileId) {
|
||||
driveFile = await this.driveFilesRepository.findOneBy({ id: ps.fileId });
|
||||
if (driveFile == null) throw new ApiError(meta.errors.noSuchFile);
|
||||
}
|
||||
|
||||
const emoji = await this.customEmojiService.getEmojiDraftById(ps.id);
|
||||
const emoji = await this.customEmojiService.getEmojiRequestById(ps.id);
|
||||
if (emoji != null) {
|
||||
if (ps.name !== emoji.name) {
|
||||
const isDuplicate = await this.customEmojiService.checkDraftDuplicate(ps.name);
|
||||
const isDuplicate = await this.customEmojiService.checkRequestDuplicate(ps.name);
|
||||
if (isDuplicate) throw new ApiError(meta.errors.sameNameEmojiExists);
|
||||
}
|
||||
} else {
|
||||
throw new ApiError(meta.errors.noSuchEmoji);
|
||||
}
|
||||
if (!isDraft) {
|
||||
if (!isRequest) {
|
||||
const file = await this.driveFileEntityService.getFromUrl(emoji.originalUrl);
|
||||
if (file === null) throw new ApiError(meta.errors.noSuchFile);
|
||||
await this.customEmojiService.add({
|
||||
|
|
@ -101,9 +101,9 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
localOnly: ps.localOnly ?? false,
|
||||
roleIdsThatCanBeUsedThisEmojiAsReaction: [],
|
||||
}, me);
|
||||
await this.customEmojiService.draftDelete(ps.id);
|
||||
await this.customEmojiService.RequestDelete(ps.id);
|
||||
} else {
|
||||
await this.customEmojiService.draftUpdate(ps.id, {
|
||||
await this.customEmojiService.RequestUpdate(ps.id, {
|
||||
name: ps.name,
|
||||
category: ps.category ?? null,
|
||||
aliases: ps.aliases ?? [],
|
||||
|
|
@ -7,7 +7,7 @@ import { Inject, Injectable } from '@nestjs/common';
|
|||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js';
|
||||
import { CustomEmojiService } from '@/core/CustomEmojiService.js';
|
||||
import type { DriveFilesRepository, EmojiDraftsRepository } from '@/models/_.js';
|
||||
import type { DriveFilesRepository } from '@/models/_.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { ApiError } from '../../../error.js';
|
||||
|
||||
|
|
@ -56,7 +56,7 @@ export const paramDef = {
|
|||
roleIdsThatCanBeUsedThisEmojiAsReaction: { type: 'array', items: {
|
||||
type: 'string',
|
||||
} },
|
||||
draft: { type: 'boolean' },
|
||||
Request: { type: 'boolean' },
|
||||
},
|
||||
required: ['id', 'name', 'aliases'],
|
||||
} as const;
|
||||
|
|
@ -72,7 +72,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
let driveFile;
|
||||
const isDraft = !!ps.draft;
|
||||
const isRequest = !!ps.Request;
|
||||
if (ps.fileId) {
|
||||
driveFile = await this.driveFilesRepository.findOneBy({ id: ps.fileId });
|
||||
if (driveFile == null) throw new ApiError(meta.errors.noSuchFile);
|
||||
|
|
@ -87,7 +87,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
throw new ApiError(meta.errors.noSuchEmoji);
|
||||
}
|
||||
|
||||
if (!isDraft) {
|
||||
if (!isRequest) {
|
||||
await this.customEmojiService.update(ps.id, {
|
||||
driveFile,
|
||||
name: ps.name,
|
||||
|
|
@ -101,7 +101,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
} else {
|
||||
const file = await this.driveFileEntityService.getFromUrl(emoji.originalUrl);
|
||||
if (file === null) throw new ApiError(meta.errors.noSuchFile);
|
||||
await this.customEmojiService.draft({
|
||||
await this.customEmojiService.Request({
|
||||
driveFile: file,
|
||||
name: ps.name,
|
||||
category: ps.category ?? null,
|
||||
|
|
|
|||
|
|
@ -3,11 +3,10 @@
|
|||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { IsNull } from 'typeorm';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import type { EmojiDraftsRepository } from '@/models/_.js';
|
||||
import type { EmojiRequestsRepository } from '@/models/_.js';
|
||||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import { EmojiDraftsEntityService } from '@/core/entities/EmojiDraftsEntityService.js';
|
||||
import { EmojiRequestsEntityService } from '@/core/entities/EmojiRequestsEntityService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
|
||||
export const meta = {
|
||||
|
|
@ -27,7 +26,7 @@ export const meta = {
|
|||
items: {
|
||||
type: 'object',
|
||||
optional: false, nullable: false,
|
||||
ref: 'EmojiDraftSimple',
|
||||
ref: 'EmojiRequestSimple',
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
@ -44,13 +43,13 @@ export const paramDef = {
|
|||
@Injectable()
|
||||
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
||||
constructor(
|
||||
@Inject(DI.emojiDraftsRepository)
|
||||
private emojiDraftsRepository: EmojiDraftsRepository,
|
||||
@Inject(DI.emojiRequestsRepository)
|
||||
private emojiRequestsRepository: EmojiRequestsRepository,
|
||||
|
||||
private emojiDraftsEntityService: EmojiDraftsEntityService,
|
||||
private emojiRequestsEntityService: EmojiRequestsEntityService,
|
||||
) {
|
||||
super(meta, paramDef, async () => {
|
||||
const emojis = await this.emojiDraftsRepository.find({
|
||||
const emojis = await this.emojiRequestsRepository.find({
|
||||
order: {
|
||||
category: 'ASC',
|
||||
name: 'ASC',
|
||||
|
|
@ -58,7 +57,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
});
|
||||
|
||||
return {
|
||||
emojis: await this.emojiDraftsEntityService.packSimpleMany(emojis),
|
||||
emojis: await this.emojiRequestsEntityService.packSimpleMany(emojis),
|
||||
};
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue