MCPcopy Create free account
hub / github.com/bewcloud/bewcloud / create

Method create

lib/models/user.ts:52–90  ·  view source on GitHub ↗
(email: User['email'], hashedPassword: User['hashed_password'])

Source from the content-addressed store, hash-verified

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(

Callers 15

simplewebauthn.jsFile · 0.45
zFunction · 0.45
FFunction · 0.45
constructorMethod · 0.45
JoFunction · 0.45
laFunction · 0.45
getOptionScopesMethod · 0.45
postFunction · 0.45
getFunction · 0.45
postFunction · 0.45
postFunction · 0.45
getFunction · 0.45

Calls 3

isThereAnAdminMethod · 0.95

Tested by

no test coverage detected