1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2025-01-08 02:43:59 +09:00
cherrypick/src/server/api/endpoints/i/authorized_apps.ts
syuilo 2756f553c6
Improve error handling of API (#4345)
* wip

* wip

* wip

* Update attached_notes.ts

* wip

* Refactor

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Update call.ts

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* ✌️

* Fix
2019-02-22 11:46:58 +09:00

46 lines
805 B
TypeScript

import $ from 'cafy';
import AccessToken from '../../../../models/access-token';
import { pack } from '../../../../models/app';
import define from '../../define';
export const meta = {
requireCredential: true,
secure: true,
params: {
limit: {
validator: $.optional.num.range(1, 100),
default: 10,
},
offset: {
validator: $.optional.num.min(0),
default: 0,
},
sort: {
validator: $.optional.str.or('desc|asc'),
default: 'desc',
}
}
};
export default define(meta, async (ps, user) => {
// Get tokens
const tokens = await AccessToken
.find({
userId: user._id
}, {
limit: ps.limit,
skip: ps.offset,
sort: {
_id: ps.sort == 'asc' ? 1 : -1
}
});
return await Promise.all(tokens.map(token => pack(token.appId, user, {
detail: true
})));
});