(email: User['email'], hashedPassword: User['hashed_password'])
| 50 | } |
| 51 | |
| 52 | static async create(email: User['email'], hashedPassword: User['hashed_password']) { |
| 53 | const trialDays = await AppConfig.isForeverSignupEnabled() ? 36_525 : 30; |
| 54 | const now = new Date(); |
| 55 | const trialEndDate = new Date(new Date().setUTCDate(new Date().getUTCDate() + trialDays)); |
| 56 | |
| 57 | const subscription: User['subscription'] = { |
| 58 | external: {}, |
| 59 | expires_at: trialEndDate.toISOString(), |
| 60 | updated_at: now.toISOString(), |
| 61 | }; |
| 62 | |
| 63 | const extra: User['extra'] = { is_email_verified: (await AppConfig.isEmailVerificationEnabled()) ? false : true }; |
| 64 | |
| 65 | // First signup will be an admin "forever" |
| 66 | if (!(await this.isThereAnAdmin())) { |
| 67 | extra.is_admin = true; |
| 68 | subscription.expires_at = new Date('2100-12-31').toISOString(); |
| 69 | } |
| 70 | |
| 71 | const newUser = (await db.query<User>( |
| 72 | sql`INSERT INTO "bewcloud_users" ( |
| 73 | "email", |
| 74 | "subscription", |
| 75 | "status", |
| 76 | "hashed_password", |
| 77 | "extra" |
| 78 | ) VALUES ($1, $2, $3, $4, $5) |
| 79 | RETURNING *`, |
| 80 | [ |
| 81 | email, |
| 82 | JSON.stringify(subscription), |
| 83 | (extra.is_admin || (await AppConfig.isForeverSignupEnabled())) ? 'active' : 'trial', |
| 84 | hashedPassword, |
| 85 | JSON.stringify(extra), |
| 86 | ], |
| 87 | ))[0]; |
| 88 | |
| 89 | return newUser; |
| 90 | } |
| 91 | |
| 92 | static async update(user: User) { |
| 93 | await db.query( |
no test coverage detected