From 37a4e5f4fce8004864720a3ed87eaff03d5c0685 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 26 Jan 2022 00:51:26 +0900 Subject: [PATCH] refactor(backend): use insert instead of save --- packages/backend/src/server/api/endpoints/app/create.ts | 4 ++-- packages/backend/src/server/api/endpoints/channels/create.ts | 4 ++-- packages/backend/src/server/api/endpoints/i/2fa/key-done.ts | 2 +- .../backend/src/server/api/endpoints/i/2fa/register-key.ts | 2 +- packages/backend/src/services/following/requests/create.ts | 4 ++-- .../backend/src/services/register-or-fetch-instance-doc.ts | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/app/create.ts b/packages/backend/src/server/api/endpoints/app/create.ts index 838cbf606e..fbe6690f1d 100644 --- a/packages/backend/src/server/api/endpoints/app/create.ts +++ b/packages/backend/src/server/api/endpoints/app/create.ts @@ -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, diff --git a/packages/backend/src/server/api/endpoints/channels/create.ts b/packages/backend/src/server/api/endpoints/channels/create.ts index 48be728d99..68cdf1143e 100644 --- a/packages/backend/src/server/api/endpoints/channels/create.ts +++ b/packages/backend/src/server/api/endpoints/channels/create.ts @@ -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); }); diff --git a/packages/backend/src/server/api/endpoints/i/2fa/key-done.ts b/packages/backend/src/server/api/endpoints/i/2fa/key-done.ts index 271632d362..26e9a60886 100644 --- a/packages/backend/src/server/api/endpoints/i/2fa/key-done.ts +++ b/packages/backend/src/server/api/endpoints/i/2fa/key-done.ts @@ -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(), diff --git a/packages/backend/src/server/api/endpoints/i/2fa/register-key.ts b/packages/backend/src/server/api/endpoints/i/2fa/register-key.ts index b6b0fd50b4..057e54c69b 100644 --- a/packages/backend/src/server/api/endpoints/i/2fa/register-key.ts +++ b/packages/backend/src/server/api/endpoints/i/2fa/register-key.ts @@ -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'), diff --git a/packages/backend/src/services/following/requests/create.ts b/packages/backend/src/services/following/requests/create.ts index cc1abcce19..e45023015d 100644 --- a/packages/backend/src/services/following/requests/create.ts +++ b/packages/backend/src/services/following/requests/create.ts @@ -25,7 +25,7 @@ export default async function(follower: { id: User['id']; host: User['host']; ur if (blocking != null) throw new Error('blocking'); if (blocked != null) throw new Error('blocked'); - const followRequest = await FollowRequests.save({ + const followRequest = await FollowRequests.insert({ id: genId(), createdAt: new Date(), followerId: follower.id, @@ -39,7 +39,7 @@ export default async function(follower: { id: User['id']; host: User['host']; ur followeeHost: followee.host, followeeInbox: Users.isRemoteUser(followee) ? followee.inbox : undefined, followeeSharedInbox: Users.isRemoteUser(followee) ? followee.sharedInbox : undefined, - }); + }).then(x => FollowRequests.findOneOrFail(x.identifiers[0])); // Publish receiveRequest event if (Users.isLocalUser(followee)) { diff --git a/packages/backend/src/services/register-or-fetch-instance-doc.ts b/packages/backend/src/services/register-or-fetch-instance-doc.ts index a548ab0497..18b42ed15b 100644 --- a/packages/backend/src/services/register-or-fetch-instance-doc.ts +++ b/packages/backend/src/services/register-or-fetch-instance-doc.ts @@ -16,12 +16,12 @@ export async function registerOrFetchInstanceDoc(host: string): Promise Instances.findOneOrFail(x.identifiers[0])); federationChart.update(true);