summaryrefslogtreecommitdiff
path: root/src/models/repositories/clip.ts
blob: 9644ceec7e7267c1c0f98da92691b73392dabe5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { EntityRepository, Repository } from 'typeorm';
import { Clip } from '../entities/clip';
import { ensure } from '../../prelude/ensure';
import { SchemaType } from '../../misc/schema';

export type PackedClip = SchemaType<typeof packedClipSchema>;

@EntityRepository(Clip)
export class ClipRepository extends Repository<Clip> {
	public async pack(
		src: Clip['id'] | Clip,
	): Promise<PackedClip> {
		const clip = typeof src === 'object' ? src : await this.findOne(src).then(ensure);

		return {
			id: clip.id,
			createdAt: clip.createdAt.toISOString(),
			name: clip.name,
		};
	}
}

export const packedClipSchema = {
	type: 'object' as const,
	optional: false as const, nullable: false as const,
	properties: {
		id: {
			type: 'string' as const,
			optional: false as const, nullable: false as const,
			format: 'id',
			description: 'The unique identifier for this Clip.',
			example: 'xxxxxxxxxx',
		},
		createdAt: {
			type: 'string' as const,
			optional: false as const, nullable: false as const,
			format: 'date-time',
			description: 'The date that the Clip was created.'
		},
		name: {
			type: 'string' as const,
			optional: false as const, nullable: false as const,
			description: 'The name of the Clip.'
		},
	},
};