FoundKey/packages/backend/src/models/repositories/app.ts
Johann150 6ce4b3fe2f
Some checks failed
ci/woodpecker/push/lint-backend Pipeline was successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/lint-client Pipeline failed
ci/woodpecker/push/test Pipeline failed
fix some lints
Many of these were fixed automatically with eslint --fix.

Some of them (e.g. adding return types to functions) were done manually.
2022-08-11 00:09:29 +02:00

41 lines
1 KiB
TypeScript

import { db } from '@/db/postgre.js';
import { Packed } from '@/misc/schema.js';
import { App } from '@/models/entities/app.js';
import { AccessTokens } from '../index.js';
import { User } from '../entities/user.js';
export const AppRepository = db.getRepository(App).extend({
async pack(
src: App['id'] | App,
me?: { id: User['id'] } | null | undefined,
options?: {
detail?: boolean,
includeSecret?: boolean,
includeProfileImageIds?: boolean
},
): Promise<Packed<'App'>> {
const opts = Object.assign({
detail: false,
includeSecret: false,
includeProfileImageIds: false,
}, options);
const app = typeof src === 'object' ? src : await this.findOneByOrFail({ id: src });
return {
id: app.id,
name: app.name,
description: app.description,
callbackUrl: app.callbackUrl,
permission: app.permission,
...(opts.includeSecret ? { secret: app.secret } : {}),
...(me ? {
isAuthorized: await AccessTokens.countBy({
appId: app.id,
userId: me.id,
}).then(count => count > 0),
} : {}),
};
},
});