forked from FoundKeyGang/FoundKey
use count instead of find to check existence
This commit is contained in:
parent
d28931bf00
commit
7bf4d4426a
1 changed files with 6 additions and 5 deletions
|
@ -7,6 +7,8 @@ import { ApiError } from '../../error.js';
|
||||||
export const meta = {
|
export const meta = {
|
||||||
tags: ['channels'],
|
tags: ['channels'],
|
||||||
|
|
||||||
|
description: 'Creates a new channel with the current user as its administrator.',
|
||||||
|
|
||||||
requireCredential: true,
|
requireCredential: true,
|
||||||
|
|
||||||
kind: 'write:channels',
|
kind: 'write:channels',
|
||||||
|
@ -32,14 +34,13 @@ export const paramDef = {
|
||||||
|
|
||||||
// eslint-disable-next-line import/no-default-export
|
// eslint-disable-next-line import/no-default-export
|
||||||
export default define(meta, paramDef, async (ps, user) => {
|
export default define(meta, paramDef, async (ps, user) => {
|
||||||
let banner = null;
|
|
||||||
if (ps.bannerId != null) {
|
if (ps.bannerId != null) {
|
||||||
banner = await DriveFiles.findOneBy({
|
const bannerExists = await DriveFiles.countBy({
|
||||||
id: ps.bannerId,
|
id: ps.bannerId,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (banner == null) throw new ApiError('NO_SUCH_FILE');
|
if (!bannerExists) throw new ApiError('NO_SUCH_FILE');
|
||||||
}
|
}
|
||||||
|
|
||||||
const channel = await Channels.insert({
|
const channel = await Channels.insert({
|
||||||
|
@ -47,8 +48,8 @@ export default define(meta, paramDef, async (ps, user) => {
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
name: ps.name,
|
name: ps.name,
|
||||||
description: ps.description || null,
|
description: ps.description,
|
||||||
bannerId: banner ? banner.id : null,
|
bannerId: ps.bannerId,
|
||||||
} as Channel).then(x => Channels.findOneByOrFail(x.identifiers[0]));
|
} as Channel).then(x => Channels.findOneByOrFail(x.identifiers[0]));
|
||||||
|
|
||||||
return await Channels.pack(channel, user);
|
return await Channels.pack(channel, user);
|
||||||
|
|
Loading…
Reference in a new issue