2019-04-07 14:50:36 +02:00
|
|
|
import { EntityRepository, Repository } from 'typeorm';
|
|
|
|
import { Users } from '..';
|
|
|
|
import { Muting } from '../entities/muting';
|
2019-04-23 15:35:26 +02:00
|
|
|
import { awaitAll } from '../../prelude/await-all';
|
2021-03-23 09:43:07 +01:00
|
|
|
import { SchemaType } from '@/misc/schema';
|
2021-03-24 03:05:37 +01:00
|
|
|
import { User } from '../entities/user';
|
2019-04-23 15:35:26 +02:00
|
|
|
|
|
|
|
export type PackedMuting = SchemaType<typeof packedMutingSchema>;
|
2019-04-07 14:50:36 +02:00
|
|
|
|
|
|
|
@EntityRepository(Muting)
|
|
|
|
export class MutingRepository extends Repository<Muting> {
|
|
|
|
public async pack(
|
|
|
|
src: Muting['id'] | Muting,
|
2021-03-24 03:05:37 +01:00
|
|
|
me?: { id: User['id'] } | null | undefined
|
2019-04-23 15:35:26 +02:00
|
|
|
): Promise<PackedMuting> {
|
2021-02-13 07:33:38 +01:00
|
|
|
const muting = typeof src === 'object' ? src : await this.findOneOrFail(src);
|
2019-04-07 14:50:36 +02:00
|
|
|
|
2019-04-23 15:35:26 +02:00
|
|
|
return await awaitAll({
|
2019-04-07 14:50:36 +02:00
|
|
|
id: muting.id,
|
2019-04-23 15:35:26 +02:00
|
|
|
createdAt: muting.createdAt.toISOString(),
|
|
|
|
muteeId: muting.muteeId,
|
2019-04-07 14:50:36 +02:00
|
|
|
mutee: Users.pack(muting.muteeId, me, {
|
|
|
|
detail: true
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
2019-04-25 06:27:07 +02:00
|
|
|
|
|
|
|
public packMany(
|
|
|
|
mutings: any[],
|
2021-03-24 03:05:37 +01:00
|
|
|
me: { id: User['id'] }
|
2019-04-25 06:27:07 +02:00
|
|
|
) {
|
|
|
|
return Promise.all(mutings.map(x => this.pack(x, me)));
|
|
|
|
}
|
2019-04-07 14:50:36 +02:00
|
|
|
}
|
2019-04-23 15:35:26 +02:00
|
|
|
|
|
|
|
export const packedMutingSchema = {
|
2019-06-27 11:04:09 +02:00
|
|
|
type: 'object' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
2019-04-23 15:35:26 +02:00
|
|
|
properties: {
|
|
|
|
id: {
|
2019-06-27 11:04:09 +02:00
|
|
|
type: 'string' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
2019-04-23 15:35:26 +02:00
|
|
|
format: 'id',
|
|
|
|
description: 'The unique identifier for this muting.',
|
|
|
|
example: 'xxxxxxxxxx',
|
|
|
|
},
|
|
|
|
createdAt: {
|
2019-06-27 11:04:09 +02:00
|
|
|
type: 'string' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
2019-04-23 15:35:26 +02:00
|
|
|
format: 'date-time',
|
|
|
|
description: 'The date that the muting was created.'
|
|
|
|
},
|
|
|
|
muteeId: {
|
2019-06-27 11:04:09 +02:00
|
|
|
type: 'string' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
2019-04-23 15:35:26 +02:00
|
|
|
format: 'id',
|
|
|
|
},
|
|
|
|
mutee: {
|
2019-06-27 11:04:09 +02:00
|
|
|
type: 'object' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
2019-04-23 15:35:26 +02:00
|
|
|
ref: 'User',
|
|
|
|
description: 'The mutee.'
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|