add reversiMatching

This commit is contained in:
tamaina 2021-09-12 21:44:32 +09:00
parent ce0f3741b9
commit ef98e4ab4f
1 changed files with 44 additions and 4 deletions

View File

@ -3,21 +3,21 @@ import { ReversiMatching } from '@/models/entities/games/reversi/matching';
import { Users } from '../../../index'; import { Users } from '../../../index';
import { awaitAll } from '@/prelude/await-all'; import { awaitAll } from '@/prelude/await-all';
import { User } from '@/models/entities/user'; import { User } from '@/models/entities/user';
import { Resolved } from '@/prelude/types'; import { SchemaType } from '@/misc/schema';
export type PackedReversiMatching = Resolved<ReturnType<ReversiMatchingRepository['pack']>>; export type PackedReversiMatching = SchemaType<typeof packedReversiMatchingSchema>;
@EntityRepository(ReversiMatching) @EntityRepository(ReversiMatching)
export class ReversiMatchingRepository extends Repository<ReversiMatching> { export class ReversiMatchingRepository extends Repository<ReversiMatching> {
public async pack( public async pack(
src: ReversiMatching['id'] | ReversiMatching, src: ReversiMatching['id'] | ReversiMatching,
me: { id: User['id'] } me: { id: User['id'] }
) { ): Promise<PackedReversiMatching> {
const matching = typeof src === 'object' ? src : await this.findOneOrFail(src); const matching = typeof src === 'object' ? src : await this.findOneOrFail(src);
return await awaitAll({ return await awaitAll({
id: matching.id, id: matching.id,
createdAt: matching.createdAt, createdAt: matching.createdAt.toISOString(),
parentId: matching.parentId, parentId: matching.parentId,
parent: Users.pack(matching.parentId, me, { parent: Users.pack(matching.parentId, me, {
detail: true detail: true
@ -29,3 +29,43 @@ export class ReversiMatchingRepository extends Repository<ReversiMatching> {
}); });
} }
} }
export const packedReversiMatchingSchema = {
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',
example: 'xxxxxxxxxx',
},
createdAt: {
type: 'string' as const,
optional: false as const, nullable: false as const,
format: 'date-time',
},
parentId: {
type: 'string' as const,
optional: false as const, nullable: false as const,
format: 'id',
example: 'xxxxxxxxxx',
},
parent: {
type: 'object' as const,
optional: false as const, nullable: true as const,
ref: 'User' as const,
},
childId: {
type: 'string' as const,
optional: false as const, nullable: false as const,
format: 'id',
example: 'xxxxxxxxxx',
},
child: {
type: 'object' as const,
optional: false as const, nullable: false as const,
ref: 'User' as const,
},
}
};