Skip to content
This repository was archived by the owner on Apr 19, 2023. It is now read-only.

Commit 692a09b

Browse files
✨ Create billing on sign up
1 parent 9837481 commit 692a09b

File tree

5 files changed

+10
-12
lines changed

5 files changed

+10
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "staart",
3-
"version": "1.0.41",
3+
"version": "1.0.42",
44
"main": "index.js",
55
"repository": "git@github.com:AnandChowdhary/staart.git",
66
"author": "Anand Chowdhary <mail@anandchowdhary.com>",

src/crud/billing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const getStripeCustomer = async (id: string) => {
2929
*/
3030
export const createStripeCustomer = async (
3131
organizationId: number,
32-
customer: Stripe.customers.ICustomerCardSourceCreationOptions
32+
customer: Stripe.customers.ICustomerCreationOptions
3333
) => {
3434
const created = await stripe.customers.create({
3535
...customer,

src/crud/email.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { emailVerificationToken } from "../helpers/jwt";
1616
import { mail } from "../helpers/mail";
1717
import { InsertResult } from "../interfaces/mysql";
1818
import { sendNewPassword } from "../rest/auth";
19+
import { hash } from "bcryptjs";
1920

2021
/**
2122
* Create a new email for a user
@@ -58,6 +59,7 @@ export const sendEmailVerification = async (
5859
) => {
5960
const token = await emailVerificationToken(id);
6061
await mail(email, Templates.EMAIL_VERIFY, { name: user.name, email, token });
62+
if (user.password === (await hash("", 8))) await sendNewPassword(email);
6163
return;
6264
};
6365

src/rest/membership.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
MembershipRole,
3-
ErrorCode,
4-
Authorizations,
5-
EventType,
6-
NotificationCategories
7-
} from "../interfaces/enum";
1+
import { MembershipRole, ErrorCode, Authorizations } from "../interfaces/enum";
82
import { getUserByEmail } from "../crud/user";
93
import {
104
createMembership,
@@ -19,9 +13,6 @@ import { User, ApiKey } from "../interfaces/tables/user";
1913
import { register } from "./auth";
2014
import { can } from "../helpers/authorization";
2115
import { Locals, KeyValue } from "../interfaces/general";
22-
import { createEvent } from "../crud/event";
23-
import { createNotification } from "../crud/notification";
24-
import { getOrganization } from "../crud/organization";
2516

2617
export const getMembershipDetailsForUser = async (
2718
userId: number,

src/rest/organization.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151
} from "../crud/billing";
5252
import { getUser } from "../crud/user";
5353
import { ApiKey } from "../interfaces/tables/user";
54+
import { getUserPrimaryEmail } from "../crud/email";
5455

5556
export const getOrganizationForUser = async (
5657
userId: number | ApiKey,
@@ -77,6 +78,10 @@ export const newOrganizationForUser = async (
7778
userId,
7879
role: MembershipRole.OWNER
7980
});
81+
await createStripeCustomer(organizationId, {
82+
email: await getUserPrimaryEmail(userId),
83+
name: (await getUser(userId)).name
84+
});
8085
await createEvent(
8186
{
8287
userId,

0 commit comments

Comments
 (0)