2020-01-29 21:37:25 +02:00
|
|
|
import $ from 'cafy';
|
|
|
|
import { ID } from '../../../../misc/cafy-id';
|
|
|
|
import define from '../../define';
|
|
|
|
import { Antennas, Notes, AntennaNotes } from '../../../../models';
|
|
|
|
import { makePaginationQuery } from '../../common/make-pagination-query';
|
|
|
|
import { generateVisibilityQuery } from '../../common/generate-visibility-query';
|
2020-07-28 03:38:41 +03:00
|
|
|
import { generateMutedUserQuery } from '../../common/generate-muted-user-query';
|
2020-01-29 21:37:25 +02:00
|
|
|
import { ApiError } from '../../error';
|
|
|
|
|
|
|
|
export const meta = {
|
2021-03-06 15:34:11 +02:00
|
|
|
desc: {
|
|
|
|
'ja-JP': '指定したアンテナのノート一覧を表示します。',
|
|
|
|
'en-US': 'Displays a list of notes for the specified antenna.'
|
|
|
|
},
|
|
|
|
|
2020-04-03 16:42:29 +03:00
|
|
|
tags: ['antennas', 'account', 'notes'],
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2020-02-15 14:33:32 +02:00
|
|
|
requireCredential: true as const,
|
2020-01-29 21:37:25 +02:00
|
|
|
|
|
|
|
kind: 'read:account',
|
|
|
|
|
|
|
|
params: {
|
|
|
|
antennaId: {
|
|
|
|
validator: $.type(ID),
|
|
|
|
},
|
|
|
|
|
|
|
|
limit: {
|
|
|
|
validator: $.optional.num.range(1, 100),
|
|
|
|
default: 10
|
|
|
|
},
|
|
|
|
|
|
|
|
sinceId: {
|
|
|
|
validator: $.optional.type(ID),
|
|
|
|
},
|
|
|
|
|
|
|
|
untilId: {
|
|
|
|
validator: $.optional.type(ID),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchAntenna: {
|
|
|
|
message: 'No such antenna.',
|
|
|
|
code: 'NO_SUCH_ANTENNA',
|
|
|
|
id: '850926e0-fd3b-49b6-b69a-b28a5dbd82fe'
|
|
|
|
}
|
2021-03-06 15:34:11 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
|
|
|
type: 'array' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
items: {
|
|
|
|
type: 'object' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
ref: 'Note'
|
|
|
|
}
|
2020-01-29 21:37:25 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default define(meta, async (ps, user) => {
|
|
|
|
const antenna = await Antennas.findOne({
|
|
|
|
id: ps.antennaId,
|
|
|
|
userId: user.id
|
|
|
|
});
|
|
|
|
|
|
|
|
if (antenna == null) {
|
|
|
|
throw new ApiError(meta.errors.noSuchAntenna);
|
|
|
|
}
|
|
|
|
|
|
|
|
const antennaQuery = AntennaNotes.createQueryBuilder('joining')
|
|
|
|
.select('joining.noteId')
|
|
|
|
.where('joining.antennaId = :antennaId', { antennaId: antenna.id });
|
|
|
|
|
|
|
|
const query = makePaginationQuery(Notes.createQueryBuilder('note'), ps.sinceId, ps.untilId)
|
|
|
|
.andWhere(`note.id IN (${ antennaQuery.getQuery() })`)
|
|
|
|
.leftJoinAndSelect('note.user', 'user')
|
|
|
|
.setParameters(antennaQuery.getParameters());
|
|
|
|
|
|
|
|
generateVisibilityQuery(query, user);
|
2020-07-28 03:38:41 +03:00
|
|
|
generateMutedUserQuery(query, user);
|
2020-01-29 21:37:25 +02:00
|
|
|
|
|
|
|
const notes = await query
|
|
|
|
.take(ps.limit!)
|
|
|
|
.getMany();
|
|
|
|
|
|
|
|
return await Notes.packMany(notes, user);
|
|
|
|
});
|