Skip to content

Commit 78b3c8b

Browse files
committed
feat: add endpoint to toggle auto-billing for users
1 parent 963330b commit 78b3c8b

11 files changed

Lines changed: 132 additions & 84 deletions

File tree

prisma/generated/edge.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prisma/generated/index-browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ exports.Prisma.UserScalarFieldEnum = {
129129
avatar: 'avatar',
130130
points: 'points',
131131
role: 'role',
132-
isAutoRenewal: 'isAutoRenewal',
132+
isAutoBilling: 'isAutoBilling',
133133
createdAt: 'createdAt',
134134
updatedAt: 'updatedAt'
135135
};

prisma/generated/index.d.ts

Lines changed: 69 additions & 69 deletions
Large diffs are not rendered by default.

prisma/generated/index.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prisma/generated/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "prisma-client-6b6ea7b36b37a418a8df6c951eb165c28b7625d99a035dd6de97a21feb8159e5",
2+
"name": "prisma-client-7aa3e4e4f748ee7c0e732b5d1c8520f7f8e7a1f6bad569d997a742cdb1e87f84",
33
"main": "index.js",
44
"types": "index.d.ts",
55
"browser": "index-browser.js",

prisma/generated/schema.prisma

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ model User {
2222
2323
role UserRole @default(STUDENT)
2424
25-
isAutoRenewal Boolean @default(false) @map("is_auto_renewal")
25+
isAutoBilling Boolean @default(false) @map("is_auto_billing")
2626
2727
emailVerification EmailVerification?
2828
passwordReset PasswordReset?
@@ -251,10 +251,10 @@ model DownloadLog {
251251
downloadedAt DateTime @default(now()) @map("downloaded_at")
252252
253253
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
254-
userId String @map("course_id")
254+
userId String @map("user_id")
255255
256256
course Course @relation(fields: [courseId], references: [id], onDelete: Cascade)
257-
courseId String @map("course_ud")
257+
courseId String @map("course_id")
258258
259259
createdAt DateTime @default(now())
260260
updatedAt DateTime @updatedAt

prisma/generated/wasm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ exports.Prisma.UserScalarFieldEnum = {
129129
avatar: 'avatar',
130130
points: 'points',
131131
role: 'role',
132-
isAutoRenewal: 'isAutoRenewal',
132+
isAutoBilling: 'isAutoBilling',
133133
createdAt: 'createdAt',
134134
updatedAt: 'updatedAt'
135135
};

src/api/auth/account/account.service.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,22 @@ export class AccountService {
3838
}
3939
})
4040

41+
const isPremium = !!(await this.prismaService.subscription.findUnique({
42+
where: {
43+
userId: user.id
44+
}
45+
}))
46+
4147
return {
4248
id: user.id,
4349
displayName: user.displayName,
4450
email: user.email,
4551
avatar: user.avatar,
4652
isEmailVerified: emailVerification
4753
? emailVerification.status === EmailVerificationStatus.VERIFIED
48-
: false
54+
: false,
55+
isAutoBilling: user.isAutoBilling,
56+
isPremium
4957
}
5058
}
5159

src/api/auth/account/dto/account.dto.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,16 @@ export class AccountResponse {
3131
example: true
3232
})
3333
public isEmailVerified: boolean
34+
35+
@ApiProperty({
36+
description: 'Indicates whether auto billing is enabled for the user',
37+
example: false
38+
})
39+
public isAutoBilling: boolean
40+
41+
@ApiProperty({
42+
description: 'Indicates whether the user has an active subscription',
43+
example: true
44+
})
45+
public isPremium: boolean
3446
}

src/api/users/users.controller.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,16 @@ export class UsersController {
166166

167167
return this.usersService.changeAvatar(user, file)
168168
}
169+
170+
@ApiOperation({
171+
summary: 'Toggle Auto Billing',
172+
description:
173+
'Enable or disable auto billing for the authenticated user (toggles current state).'
174+
})
175+
@Authorization()
176+
@Patch('@me/billing')
177+
@HttpCode(HttpStatus.OK)
178+
public async toggleAutoBilling(@Authorized() user: User) {
179+
return await this.usersService.toggleAutoBilling(user)
180+
}
169181
}

0 commit comments

Comments
 (0)