Skip to content

Commit 7e9b763

Browse files
Merge pull request #930 from aakashreddy-p/fix/aakash/variable-correction
fix: corrected the variables in it.
2 parents 42d2428 + 74a0433 commit 7e9b763

File tree

6 files changed

+18
-16
lines changed

6 files changed

+18
-16
lines changed

src/modules/billing/payloads/stripe.payload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ export class CreateSubscriptionDto {
161161
description: "Indicates if the change is an upgrade or downgrade",
162162
example: true,
163163
})
164+
@IsOptional()
164165
@IsBoolean()
165-
@IsNotEmpty()
166166
isUpgrade?: boolean;
167167
}
168168

src/modules/billing/repositories/stripe-subscription.repository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ export class StripeSubscriptionRepository {
293293
*/
294294
async addDowngradeDetails(
295295
teamId: string,
296-
workspaces: Array<{ workspaceId: string; name: string }>,
296+
workspaces: Array<{ id: string; name: string }>,
297297
users: Array<{ id: string; email: string }>,
298298
downgradeType?: SubscriptionDowngradeType,
299299
): Promise<UpdateResult> {
@@ -437,7 +437,7 @@ export class StripeSubscriptionRepository {
437437
*/
438438
async addUpgradeDetails(
439439
teamId: string,
440-
workspaces: Array<{ workspaceId: string; name: string }>,
440+
workspaces: Array<{ id: string; name: string }>,
441441
): Promise<void> {
442442
try {
443443
if (!teamId) {

src/modules/billing/services/downgrade.service.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,12 @@ export class DownGradeService {
111111
return response;
112112
}
113113

114-
async restrictTeamWorkspace(teamId: string, workspaceIds: string[]) {
114+
async restrictTeamWorkspace(teamId: string, workspaceIds: string[] = []) {
115+
// If no workspaceIds passed → do nothing
116+
if (!workspaceIds || workspaceIds.length === 0) {
117+
console.log("No workspaceIds provided. Skipping restriction update.");
118+
return;
119+
}
115120
const teamObject = new ObjectId(teamId);
116121
const teamData =
117122
await this.downgradeTeamRepository.findTeamByTeamId(teamObject);
@@ -125,14 +130,11 @@ export class DownGradeService {
125130
}
126131
return workspace;
127132
});
128-
const teamUpdated = {
129-
workspaces: updatedWorkspaces,
130-
};
131-
const data = await this.downgradeTeamRepository.updateTeamById(
133+
const teamUpdated = { workspaces: updatedWorkspaces };
134+
return await this.downgradeTeamRepository.updateTeamById(
132135
teamObject,
133136
teamUpdated,
134137
);
135-
return data;
136138
}
137139

138140
/**
@@ -146,7 +148,7 @@ export class DownGradeService {
146148
*/
147149
async addDowgradeDetails(
148150
teamId: string,
149-
workspaces: Array<{ workspaceId: string; name: string }>,
151+
workspaces: Array<{ id: string; name: string }>,
150152
users: Array<{ id: string; email: string }>,
151153
) {
152154
try {
@@ -184,10 +186,10 @@ export class DownGradeService {
184186
const teamObject = new ObjectId(teamId);
185187
let workspacesToUnrestrict: WorkspaceDtoWithRestriction[] = [];
186188
let updatedWorkspaces: WorkspaceDtoWithRestriction[];
187-
if (team.upgrade && team.upgrade.workspaces.length > 0) {
189+
if (team?.upgrade && team?.upgrade.workspaces.length > 0) {
188190
// If the team is on an upgrade plan, unrestrict User select workspaces
189191
const workspacesToUnrestrictIds = new Set(
190-
team.upgrade.workspaces.map((w) => w.workspaceId.toString()),
192+
team.upgrade.workspaces.map((w) => w.id.toString()),
191193
);
192194

193195
updatedWorkspaces = team.workspaces.map((workspace) => {

src/modules/billing/services/stripe-subscription.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2151,7 +2151,7 @@ export class StripeSubscriptionService {
21512151
const OwnerEmail = team.users[0].email;
21522152
// Extract workspace IDs from downgrade list (workspaces to keep)
21532153
const downgradeWorkspaceIds =
2154-
teamDowngradeWorkspaces?.map((ws) => ws.workspaceId) || [];
2154+
teamDowngradeWorkspaces?.map((ws) => ws.id) || [];
21552155
// Extract user IDs from downgrade list (users to keep)
21562156
const downgradeUserIds = teamDowngradeUsers?.map((user) => user.id) || [];
21572157
const downgradeUserEmails =

src/modules/billing/services/upgrade.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class UpGradeService {
1919
*/
2020
async addUpgradeDetails(
2121
teamId: string,
22-
workspaces: Array<{ workspaceId: string; name: string }>,
22+
workspaces: Array<{ id: string; name: string }>,
2323
) {
2424
try {
2525
await this.stripeSubscriptionRepository.addUpgradeDetails(

src/modules/common/models/billing.model.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ export class UpgradeDetails {
206206
export class upgradeWorkspace {
207207
@IsString()
208208
@IsOptional()
209-
workspaceId: string;
209+
id: string;
210210

211211
@IsString()
212212
@IsOptional()
@@ -216,7 +216,7 @@ export class upgradeWorkspace {
216216
export class downgradeWorkspace {
217217
@IsString()
218218
@IsOptional()
219-
workspaceId: string;
219+
id: string;
220220

221221
@IsString()
222222
@IsOptional()

0 commit comments

Comments
 (0)