なんかもうめっちゃ変えた
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import define from '../../define.js';
|
||||
import { AccessTokens, Apps } from '@/models/index.js';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import { AccessTokensRepository } from '@/models/index.js';
|
||||
import { AppEntityService } from '@/core/entities/AppEntityService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@@ -12,26 +15,36 @@ export const paramDef = {
|
||||
properties: {
|
||||
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
|
||||
offset: { type: 'integer', default: 0 },
|
||||
sort: { type: 'string', enum: ['desc', 'asc'], default: "desc" },
|
||||
sort: { type: 'string', enum: ['desc', 'asc'], default: 'desc' },
|
||||
},
|
||||
required: [],
|
||||
} as const;
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, user) => {
|
||||
// Get tokens
|
||||
const tokens = await AccessTokens.find({
|
||||
where: {
|
||||
userId: user.id,
|
||||
},
|
||||
take: ps.limit,
|
||||
skip: ps.offset,
|
||||
order: {
|
||||
id: ps.sort === 'asc' ? 1 : -1,
|
||||
},
|
||||
});
|
||||
@Injectable()
|
||||
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||
constructor(
|
||||
@Inject(DI.accessTokensRepository)
|
||||
private accessTokensRepository: AccessTokensRepository,
|
||||
|
||||
return await Promise.all(tokens.map(token => Apps.pack(token.appId, user, {
|
||||
detail: true,
|
||||
})));
|
||||
});
|
||||
private appEntityService: AppEntityService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
// Get tokens
|
||||
const tokens = await this.accessTokensRepository.find({
|
||||
where: {
|
||||
userId: me.id,
|
||||
},
|
||||
take: ps.limit,
|
||||
skip: ps.offset,
|
||||
order: {
|
||||
id: ps.sort === 'asc' ? 1 : -1,
|
||||
},
|
||||
});
|
||||
|
||||
return await Promise.all(tokens.map(token => this.appEntityService.pack(token.appId, me, {
|
||||
detail: true,
|
||||
})));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user