mizzkey/src/models/repositories/blocking.ts
syuilo 987168b863
strictNullChecks (#4666)
* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip
2019-04-13 01:43:22 +09:00

30 lines
708 B
TypeScript

import { EntityRepository, Repository } from 'typeorm';
import { Users } from '..';
import rap from '@prezzemolo/rap';
import { Blocking } from '../entities/blocking';
import { ensure } from '../../prelude/ensure';
@EntityRepository(Blocking)
export class BlockingRepository extends Repository<Blocking> {
public packMany(
blockings: any[],
me: any
) {
return Promise.all(blockings.map(x => this.pack(x, me)));
}
public async pack(
src: Blocking['id'] | Blocking,
me?: any
) {
const blocking = typeof src === 'object' ? src : await this.findOne(src).then(ensure);
return await rap({
id: blocking.id,
blockee: Users.pack(blocking.blockeeId, me, {
detail: true
})
});
}
}