- Add goals feature (models, migrations, API, web pages) - Add reserved/centralized wallet balance service - Add wallet detail page and overview components - Add new UI components (progress, multi-select, FAB) - Remove stray empty -H/-d files from working tree
97 lines
3.4 KiB
JavaScript
Executable File
97 lines
3.4 KiB
JavaScript
Executable File
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.AdminPlansService = void 0;
|
|
const common_1 = require("@nestjs/common");
|
|
const prisma_service_1 = require("../prisma/prisma.service");
|
|
let AdminPlansService = class AdminPlansService {
|
|
prisma;
|
|
constructor(prisma) {
|
|
this.prisma = prisma;
|
|
}
|
|
async findAll() {
|
|
return this.prisma.plan.findMany({
|
|
orderBy: { sortOrder: 'asc' },
|
|
include: {
|
|
_count: {
|
|
select: { subscriptions: true },
|
|
},
|
|
},
|
|
});
|
|
}
|
|
async findOne(id) {
|
|
return this.prisma.plan.findUnique({
|
|
where: { id },
|
|
include: {
|
|
_count: {
|
|
select: { subscriptions: true },
|
|
},
|
|
},
|
|
});
|
|
}
|
|
async create(data) {
|
|
return this.prisma.plan.create({
|
|
data,
|
|
});
|
|
}
|
|
async update(id, data) {
|
|
return this.prisma.plan.update({
|
|
where: { id },
|
|
data,
|
|
});
|
|
}
|
|
async delete(id) {
|
|
const plan = await this.prisma.plan.findUnique({
|
|
where: { id },
|
|
include: {
|
|
_count: {
|
|
select: { subscriptions: true },
|
|
},
|
|
},
|
|
});
|
|
if (!plan) {
|
|
throw new Error('Plan not found');
|
|
}
|
|
if (plan._count.subscriptions > 0) {
|
|
return {
|
|
success: false,
|
|
message: `Cannot delete plan. There are ${plan._count.subscriptions} active subscription(s) associated with this plan. The plan has been deactivated instead.`,
|
|
action: 'deactivated',
|
|
plan: await this.prisma.plan.update({
|
|
where: { id },
|
|
data: { isActive: false, isVisible: false },
|
|
}),
|
|
};
|
|
}
|
|
await this.prisma.plan.delete({
|
|
where: { id },
|
|
});
|
|
return {
|
|
success: true,
|
|
message: 'Plan permanently deleted',
|
|
action: 'deleted',
|
|
};
|
|
}
|
|
async reorder(planIds) {
|
|
const updates = planIds.map((id, index) => this.prisma.plan.update({
|
|
where: { id },
|
|
data: { sortOrder: index + 1 },
|
|
}));
|
|
await this.prisma.$transaction(updates);
|
|
return { success: true };
|
|
}
|
|
};
|
|
exports.AdminPlansService = AdminPlansService;
|
|
exports.AdminPlansService = AdminPlansService = __decorate([
|
|
(0, common_1.Injectable)(),
|
|
__metadata("design:paramtypes", [prisma_service_1.PrismaService])
|
|
], AdminPlansService);
|
|
//# sourceMappingURL=admin-plans.service.js.map
|