Skip to content

Commit b4cbbd8

Browse files
committed
only start free trial if no license already
1 parent f75b132 commit b4cbbd8

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

repos/License.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ const getExistingSubscriptionLicenseByUserId = async (userId: string): Promise<L
7272
return result || null
7373
}
7474

75+
const getLicenseByUserId = async (userId: string): Promise<License | null> => {
76+
const result = await db(tableName)
77+
.where({ user_id: userId })
78+
.first('*')
79+
80+
return result || null
81+
}
82+
7583
const createLicense = async (data: CreateLicenseData): Promise<License> => {
7684
const [license] = await db(tableName)
7785
.insert({
@@ -126,6 +134,7 @@ export const LicenseRepo = {
126134
getActiveLicenseByUserId,
127135
getFreeTrialLicenseByUserId,
128136
getExistingSubscriptionLicenseByUserId,
137+
getLicenseByUserId,
129138
createLicense,
130139
updateLicense,
131140
deleteLicense,

services/LicenseService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const getActiveLicense = async (userId: string) => {
66
}
77

88
const startFreeTrial = async (userId: string) => {
9-
const existingLicense = await LicenseRepo.getActiveLicenseByUserId(userId)
9+
const existingLicense = await LicenseRepo.getLicenseByUserId(userId)
1010
if (existingLicense) {
1111
throw new ApiError('User already has a license', 422)
1212
}

0 commit comments

Comments
 (0)