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 = {
|
||||
tags: ['channels'],
|
||||
|
||||
description: 'Creates a new channel with the current user as its administrator.',
|
||||
|
||||
requireCredential: true,
|
||||
|
||||
kind: 'write:channels',
|
||||
|
@ -32,14 +34,13 @@ export const paramDef = {
|
|||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
let banner = null;
|
||||
if (ps.bannerId != null) {
|
||||
banner = await DriveFiles.findOneBy({
|
||||
const bannerExists = await DriveFiles.countBy({
|
||||
id: ps.bannerId,
|
||||
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({
|
||||
|
@ -47,8 +48,8 @@ export default define(meta, paramDef, async (ps, user) => {
|
|||
createdAt: new Date(),
|
||||
userId: user.id,
|
||||
name: ps.name,
|
||||
description: ps.description || null,
|
||||
bannerId: banner ? banner.id : null,
|
||||
description: ps.description,
|
||||
bannerId: ps.bannerId,
|
||||
} as Channel).then(x => Channels.findOneByOrFail(x.identifiers[0]));
|
||||
|
||||
return await Channels.pack(channel, user);
|
||||
|
|
Loading…
Reference in a new issue