-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from Duna-System/feat/StripeIntegration
fix: Add customerId in user table
- Loading branch information
Showing
16 changed files
with
141 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { IUsers } from '../../interfaces'; | ||
export declare function updateCustomerId(email: string, updates: Partial<IUsers['paymentInfo']>): Promise<IUsers | null>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.updateCustomerId = void 0; | ||
const duna_web_platform_error_defs_1 = require("duna-web-platform-error-defs"); | ||
const validationUserModel_1 = require("../validationUserModel"); | ||
function updateCustomerId(email, updates) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const filter = { email }; | ||
const update = { | ||
$set: { | ||
'paymentInfo.customerId': updates.customerId, | ||
'paymentInfo.plan': updates.plan, | ||
'paymentInfo.expirationDate': updates.expirationDate, | ||
}, | ||
}; | ||
const options = { new: true }; | ||
const updatedUser = yield validationUserModel_1.UserModel.findOneAndUpdate(filter, update, options); | ||
if (!updatedUser) { | ||
const err = duna_web_platform_error_defs_1.ErrorMessages.UserNotFound.Message; | ||
throw err; | ||
} | ||
return updatedUser; | ||
} | ||
catch (error) { | ||
console.error('Error in updateCustomerId:', error); | ||
const err = duna_web_platform_error_defs_1.ErrorMessages.InternalServerError; | ||
err.Details = 'Error updating user data.'; | ||
throw err; | ||
} | ||
}); | ||
} | ||
exports.updateCustomerId = updateCustomerId; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { ErrorMessages } from 'duna-web-platform-error-defs' | ||
import { IUsers } from '../../interfaces' | ||
import { UserModel } from '../validationUserModel' | ||
|
||
export async function updateCustomerId( | ||
email: string, | ||
updates: Partial<IUsers['paymentInfo']> | ||
): Promise<IUsers | null> { | ||
try { | ||
const filter = { email } | ||
const update = { | ||
$set: { | ||
'paymentInfo.customerId': updates.customerId, | ||
'paymentInfo.plan': updates.plan, | ||
'paymentInfo.expirationDate': updates.expirationDate, | ||
}, | ||
} | ||
|
||
const options = { new: true } | ||
|
||
const updatedUser = await UserModel.findOneAndUpdate( | ||
filter, | ||
update, | ||
options | ||
) | ||
|
||
if (!updatedUser) { | ||
const err = ErrorMessages.UserNotFound.Message | ||
throw err | ||
} | ||
|
||
return updatedUser | ||
} catch (error) { | ||
console.error('Error in updateCustomerId:', error) | ||
const err = ErrorMessages.InternalServerError | ||
err.Details = 'Error updating user data.' | ||
throw err | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters