refactor(backend): use insert instead of save

This commit is contained in:
syuilo
2022-01-26 00:51:26 +09:00
parent 91c56ceb6e
commit 37a4e5f4fc
6 changed files with 10 additions and 10 deletions

View File

@ -46,7 +46,7 @@ export default define(meta, async (ps, user) => {
const permission = unique(ps.permission.map(v => v.replace(/^(.+)(\/|-)(read|write)$/, '$3:$1')));
// Create account
const app = await Apps.save({
const app = await Apps.insert({
id: genId(),
createdAt: new Date(),
userId: user ? user.id : null,
@ -55,7 +55,7 @@ export default define(meta, async (ps, user) => {
permission,
callbackUrl: ps.callbackUrl,
secret: secret,
});
}).then(x => Apps.findOneOrFail(x.identifiers[0]));
return await Apps.pack(app, null, {
detail: true,

View File

@ -56,14 +56,14 @@ export default define(meta, async (ps, user) => {
}
}
const channel = await Channels.save({
const channel = await Channels.insert({
id: genId(),
createdAt: new Date(),
userId: user.id,
name: ps.name,
description: ps.description || null,
bannerId: banner ? banner.id : null,
} as Channel);
} as Channel).then(x => Channels.findOneOrFail(x.identifiers[0]));
return await Channels.pack(channel, user);
});

View File

@ -130,7 +130,7 @@ export default define(meta, async (ps, user) => {
const credentialIdString = credentialId.toString('hex');
await UserSecurityKeys.save({
await UserSecurityKeys.insert({
userId: user.id,
id: credentialIdString,
lastUsed: new Date(),

View File

@ -45,7 +45,7 @@ export default define(meta, async (ps, user) => {
const challengeId = genId();
await AttestationChallenges.save({
await AttestationChallenges.insert({
userId: user.id,
id: challengeId,
challenge: hash(Buffer.from(challenge, 'utf-8')).toString('hex'),