monkeeShark/src/server/api/endpoints/i.ts
syuilo 6c975275f8
Registry (#7073)
* wip

* wip

* wip

* wip

* wip

* Update registry.value.vue

* wip

* wip

* wip

* wip

* typo
2021-01-11 20:38:34 +09:00

52 lines
1.1 KiB
TypeScript

import define from '../define';
import { RegistryItems, UserProfiles, Users } from '../../../models';
import { ensure } from '../../../prelude/ensure';
import { genId } from '../../../misc/gen-id';
export const meta = {
desc: {
'ja-JP': '自分のアカウント情報を取得します。'
},
tags: ['account'],
requireCredential: true as const,
params: {},
res: {
type: 'object' as const,
optional: false as const, nullable: false as const,
ref: 'User',
},
};
export default define(meta, async (ps, user, token) => {
const isSecure = token == null;
// TODO: そのうち消す
const profile = await UserProfiles.findOne(user.id).then(ensure);
for (const [k, v] of Object.entries(profile.clientData)) {
await RegistryItems.insert({
id: genId(),
createdAt: new Date(),
updatedAt: new Date(),
userId: user.id,
domain: null,
scope: ['client', 'base'],
key: k,
value: v
});
}
await UserProfiles.createQueryBuilder().update()
.set({
clientData: {},
})
.where('userId = :id', { id: user.id })
.execute();
return await Users.pack(user, user, {
detail: true,
includeSecrets: isSecure
});
});