summaryrefslogtreecommitdiff
path: root/src/server/api/private
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2019-04-12 01:52:25 +0900
committersyuilo <syuilotan@yahoo.co.jp>2019-04-12 01:52:25 +0900
commit2ff3069d23aa688cea5a3bd204236f2f2f64c201 (patch)
tree479448f49c2204e5729ed28a1af34a86e354492b /src/server/api/private
parentトランザクションを使用してアンケートレコードの挿入... (diff)
downloadsharkey-2ff3069d23aa688cea5a3bd204236f2f2f64c201.tar.gz
sharkey-2ff3069d23aa688cea5a3bd204236f2f2f64c201.tar.bz2
sharkey-2ff3069d23aa688cea5a3bd204236f2f2f64c201.zip
トランザクションを使うようにしたり
Diffstat (limited to 'src/server/api/private')
-rw-r--r--src/server/api/private/signup.ts46
1 files changed, 26 insertions, 20 deletions
diff --git a/src/server/api/private/signup.ts b/src/server/api/private/signup.ts
index 5ed25fa411..ed4a533dec 100644
--- a/src/server/api/private/signup.ts
+++ b/src/server/api/private/signup.ts
@@ -12,6 +12,7 @@ import { User } from '../../../models/entities/user';
import { UserKeypair } from '../../../models/entities/user-keypair';
import { toPuny } from '../../../misc/convert-host';
import { UserProfile } from '../../../models/entities/user-profile';
+import { getConnection } from 'typeorm';
export default async (ctx: Koa.BaseContext) => {
const body = ctx.request.body as any;
@@ -99,28 +100,33 @@ export default async (ctx: Koa.BaseContext) => {
e ? j(e) : s([publicKey, privateKey])
));
- const account = await Users.save({
- id: genId(),
- createdAt: new Date(),
- username: username,
- usernameLower: username.toLowerCase(),
- host: toPuny(host),
- token: secret,
- isAdmin: config.autoAdmin && usersCount === 0,
- } as User);
+ let account: User;
- await UserKeypairs.save({
- publicKey: keyPair[0],
- privateKey: keyPair[1],
- userId: account.id
- } as UserKeypair);
+ // Start transaction
+ await getConnection().transaction(async transactionalEntityManager => {
+ account = await transactionalEntityManager.save(new User({
+ id: genId(),
+ createdAt: new Date(),
+ username: username,
+ usernameLower: username.toLowerCase(),
+ host: toPuny(host),
+ token: secret,
+ isAdmin: config.autoAdmin && usersCount === 0,
+ }));
- await UserProfiles.save({
- userId: account.id,
- autoAcceptFollowed: true,
- autoWatch: false,
- password: hash,
- } as Partial<UserProfile>);
+ await transactionalEntityManager.save(new UserKeypair({
+ publicKey: keyPair[0],
+ privateKey: keyPair[1],
+ userId: account.id
+ }));
+
+ await transactionalEntityManager.save(new UserProfile({
+ userId: account.id,
+ autoAcceptFollowed: true,
+ autoWatch: false,
+ password: hash,
+ }));
+ });
usersChart.update(account, true);