mirror of
https://github.com/paricafe/misskey.git
synced 2024-11-26 23:46:44 -06:00
987168b863
* wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip
49 lines
1.1 KiB
TypeScript
49 lines
1.1 KiB
TypeScript
import $ from 'cafy';
|
|
import { ID } from '../../../../../misc/cafy-id';
|
|
import define from '../../../define';
|
|
import { ReversiGames } from '../../../../../models';
|
|
import { makePaginationQuery } from '../../../common/make-pagination-query';
|
|
import { Brackets } from 'typeorm';
|
|
|
|
export const meta = {
|
|
tags: ['games'],
|
|
|
|
params: {
|
|
limit: {
|
|
validator: $.optional.num.range(1, 100),
|
|
default: 10
|
|
},
|
|
|
|
sinceId: {
|
|
validator: $.optional.type(ID),
|
|
},
|
|
|
|
untilId: {
|
|
validator: $.optional.type(ID),
|
|
},
|
|
|
|
my: {
|
|
validator: $.optional.bool,
|
|
default: false
|
|
}
|
|
}
|
|
};
|
|
|
|
export default define(meta, async (ps, user) => {
|
|
const query = makePaginationQuery(ReversiGames.createQueryBuilder('game'), ps.sinceId, ps.untilId)
|
|
.andWhere('game.isStarted = TRUE');
|
|
|
|
if (ps.my) {
|
|
query.andWhere(new Brackets(qb => { qb
|
|
.where('game.user1Id = :userId', { userId: user.id })
|
|
.orWhere('game.user2Id = :userId', { userId: user.id });
|
|
}));
|
|
}
|
|
|
|
// Fetch games
|
|
const games = await query.take(ps.limit!).getMany();
|
|
|
|
return await Promise.all(games.map((g) => ReversiGames.pack(g, user, {
|
|
detail: false
|
|
})));
|
|
});
|