save email as pdf likae attachment version 2
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
||||
{"version":3,"file":"contract.controller.d.ts","sourceRoot":"","sources":["../../src/controllers/contract.controller.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,EAAe,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE7D,wBAAsB,YAAY,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CA+BjF;AAED,wBAAsB,WAAW,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CA8BhF;AAED,wBAAsB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAU/E;AAED,wBAAsB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAU/E;AAED,wBAAsB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAU/E;AAED,wBAAsB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAU/E;AAED,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBpF;AAED,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAUtF;AAED,wBAAsB,sBAAsB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAUvF;AAED,wBAAsB,iBAAiB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AI,CAAC,CAUtF;AAED,wBAAsB,sBAAsB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAUvF;AAED,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAUlF;AAID,wBAAsB,UAAU,CAAC,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAW/E"}
|
||||
+7
-1
@@ -48,7 +48,13 @@ const contractService = __importStar(require("../services/contract.service.js"))
|
||||
const contractCockpitService = __importStar(require("../services/contractCockpit.service.js"));
|
||||
async function getContracts(req, res) {
|
||||
try {
|
||||
const { customerId, type, status, search, page, limit } = req.query;
|
||||
const { customerId, type, status, search, page, limit, tree } = req.query;
|
||||
// Baumstruktur für Kundenansicht
|
||||
if (tree === 'true' && customerId) {
|
||||
const treeData = await contractService.getContractTreeForCustomer(parseInt(customerId));
|
||||
res.json({ success: true, data: treeData });
|
||||
return;
|
||||
}
|
||||
// Für Kundenportal-Benutzer: nur eigene + vertretene Kunden-Verträge anzeigen
|
||||
let customerIds;
|
||||
if (req.user?.isCustomerPortal && req.user.customerId) {
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+107
@@ -67,6 +67,19 @@ export declare function getAllContracts(filters: ContractFilters): Promise<{
|
||||
color: string | null;
|
||||
sortOrder: number;
|
||||
} | null;
|
||||
billingAddress: {
|
||||
id: number;
|
||||
customerId: number;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
type: import(".prisma/client").$Enums.AddressType;
|
||||
isDefault: boolean;
|
||||
street: string;
|
||||
houseNumber: string;
|
||||
postalCode: string;
|
||||
city: string;
|
||||
country: string;
|
||||
} | null;
|
||||
cancellationPeriod: {
|
||||
id: number;
|
||||
isActive: boolean;
|
||||
@@ -99,6 +112,7 @@ export declare function getAllContracts(filters: ContractFilters): Promise<{
|
||||
contractNumber: string;
|
||||
contractCategoryId: number | null;
|
||||
addressId: number | null;
|
||||
billingAddressId: number | null;
|
||||
bankCardId: number | null;
|
||||
identityDocumentId: number | null;
|
||||
salesPlatformId: number | null;
|
||||
@@ -354,6 +368,19 @@ export declare function getContractById(id: number, decryptPassword?: boolean):
|
||||
color: string | null;
|
||||
sortOrder: number;
|
||||
} | null;
|
||||
billingAddress: {
|
||||
id: number;
|
||||
customerId: number;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
type: import(".prisma/client").$Enums.AddressType;
|
||||
isDefault: boolean;
|
||||
street: string;
|
||||
houseNumber: string;
|
||||
postalCode: string;
|
||||
city: string;
|
||||
country: string;
|
||||
} | null;
|
||||
cancellationPeriod: {
|
||||
id: number;
|
||||
isActive: boolean;
|
||||
@@ -490,6 +517,7 @@ export declare function getContractById(id: number, decryptPassword?: boolean):
|
||||
contractNumber: string;
|
||||
contractCategoryId: number | null;
|
||||
addressId: number | null;
|
||||
billingAddressId: number | null;
|
||||
bankCardId: number | null;
|
||||
identityDocumentId: number | null;
|
||||
salesPlatformId: number | null;
|
||||
@@ -534,6 +562,7 @@ export declare function getContractById(id: number, decryptPassword?: boolean):
|
||||
contractNumber: string;
|
||||
contractCategoryId: number | null;
|
||||
addressId: number | null;
|
||||
billingAddressId: number | null;
|
||||
bankCardId: number | null;
|
||||
identityDocumentId: number | null;
|
||||
salesPlatformId: number | null;
|
||||
@@ -563,6 +592,7 @@ interface ContractCreateData {
|
||||
contractCategoryId?: number;
|
||||
status?: ContractStatus;
|
||||
addressId?: number;
|
||||
billingAddressId?: number;
|
||||
bankCardId?: number;
|
||||
identityDocumentId?: number;
|
||||
salesPlatformId?: number;
|
||||
@@ -786,6 +816,19 @@ export declare function createContract(data: ContractCreateData): Promise<{
|
||||
internetUsername: string | null;
|
||||
internetPasswordEncrypted: string | null;
|
||||
}) | null;
|
||||
billingAddress: {
|
||||
id: number;
|
||||
customerId: number;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
type: import(".prisma/client").$Enums.AddressType;
|
||||
isDefault: boolean;
|
||||
street: string;
|
||||
houseNumber: string;
|
||||
postalCode: string;
|
||||
city: string;
|
||||
country: string;
|
||||
} | null;
|
||||
} & {
|
||||
id: number;
|
||||
customerId: number;
|
||||
@@ -802,6 +845,7 @@ export declare function createContract(data: ContractCreateData): Promise<{
|
||||
contractNumber: string;
|
||||
contractCategoryId: number | null;
|
||||
addressId: number | null;
|
||||
billingAddressId: number | null;
|
||||
bankCardId: number | null;
|
||||
identityDocumentId: number | null;
|
||||
salesPlatformId: number | null;
|
||||
@@ -1050,6 +1094,19 @@ export declare function updateContract(id: number, data: Partial<ContractCreateD
|
||||
color: string | null;
|
||||
sortOrder: number;
|
||||
} | null;
|
||||
billingAddress: {
|
||||
id: number;
|
||||
customerId: number;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
type: import(".prisma/client").$Enums.AddressType;
|
||||
isDefault: boolean;
|
||||
street: string;
|
||||
houseNumber: string;
|
||||
postalCode: string;
|
||||
city: string;
|
||||
country: string;
|
||||
} | null;
|
||||
cancellationPeriod: {
|
||||
id: number;
|
||||
isActive: boolean;
|
||||
@@ -1186,6 +1243,7 @@ export declare function updateContract(id: number, data: Partial<ContractCreateD
|
||||
contractNumber: string;
|
||||
contractCategoryId: number | null;
|
||||
addressId: number | null;
|
||||
billingAddressId: number | null;
|
||||
bankCardId: number | null;
|
||||
identityDocumentId: number | null;
|
||||
salesPlatformId: number | null;
|
||||
@@ -1230,6 +1288,7 @@ export declare function updateContract(id: number, data: Partial<ContractCreateD
|
||||
contractNumber: string;
|
||||
contractCategoryId: number | null;
|
||||
addressId: number | null;
|
||||
billingAddressId: number | null;
|
||||
bankCardId: number | null;
|
||||
identityDocumentId: number | null;
|
||||
salesPlatformId: number | null;
|
||||
@@ -1269,6 +1328,7 @@ export declare function deleteContract(id: number): Promise<{
|
||||
contractNumber: string;
|
||||
contractCategoryId: number | null;
|
||||
addressId: number | null;
|
||||
billingAddressId: number | null;
|
||||
bankCardId: number | null;
|
||||
identityDocumentId: number | null;
|
||||
salesPlatformId: number | null;
|
||||
@@ -1424,6 +1484,19 @@ export declare function createFollowUpContract(previousContractId: number): Prom
|
||||
internetUsername: string | null;
|
||||
internetPasswordEncrypted: string | null;
|
||||
}) | null;
|
||||
billingAddress: {
|
||||
id: number;
|
||||
customerId: number;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
type: import(".prisma/client").$Enums.AddressType;
|
||||
isDefault: boolean;
|
||||
street: string;
|
||||
houseNumber: string;
|
||||
postalCode: string;
|
||||
city: string;
|
||||
country: string;
|
||||
} | null;
|
||||
} & {
|
||||
id: number;
|
||||
customerId: number;
|
||||
@@ -1440,6 +1513,7 @@ export declare function createFollowUpContract(previousContractId: number): Prom
|
||||
contractNumber: string;
|
||||
contractCategoryId: number | null;
|
||||
addressId: number | null;
|
||||
billingAddressId: number | null;
|
||||
bankCardId: number | null;
|
||||
identityDocumentId: number | null;
|
||||
salesPlatformId: number | null;
|
||||
@@ -1474,5 +1548,38 @@ export declare function getInternetCredentials(contractId: number): Promise<{
|
||||
export declare function getSipCredentials(phoneNumberId: number): Promise<{
|
||||
password: string | null;
|
||||
}>;
|
||||
export interface ContractTreeNode {
|
||||
contract: {
|
||||
id: number;
|
||||
contractNumber: string;
|
||||
type: ContractType;
|
||||
status: ContractStatus;
|
||||
startDate: Date | null;
|
||||
endDate: Date | null;
|
||||
providerName: string | null;
|
||||
tariffName: string | null;
|
||||
previousContractId: number | null;
|
||||
provider?: {
|
||||
id: number;
|
||||
name: string;
|
||||
} | null;
|
||||
tariff?: {
|
||||
id: number;
|
||||
name: string;
|
||||
} | null;
|
||||
contractCategory?: {
|
||||
id: number;
|
||||
name: string;
|
||||
} | null;
|
||||
};
|
||||
predecessors: ContractTreeNode[];
|
||||
hasHistory: boolean;
|
||||
}
|
||||
/**
|
||||
* Verträge eines Kunden als Baumstruktur abrufen.
|
||||
* Wurzelknoten = Verträge ohne Nachfolger (aktuellste Verträge)
|
||||
* Vorgänger werden rekursiv eingebettet.
|
||||
*/
|
||||
export declare function getContractTreeForCustomer(customerId: number): Promise<ContractTreeNode[]>;
|
||||
export {};
|
||||
//# sourceMappingURL=contract.service.d.ts.map
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+67
-1
@@ -10,6 +10,7 @@ exports.getContractPassword = getContractPassword;
|
||||
exports.getSimCardCredentials = getSimCardCredentials;
|
||||
exports.getInternetCredentials = getInternetCredentials;
|
||||
exports.getSipCredentials = getSipCredentials;
|
||||
exports.getContractTreeForCustomer = getContractTreeForCustomer;
|
||||
const client_1 = require("@prisma/client");
|
||||
const helpers_js_1 = require("../utils/helpers.js");
|
||||
const encryption_js_1 = require("../utils/encryption.js");
|
||||
@@ -75,7 +76,7 @@ async function getAllContracts(filters) {
|
||||
where,
|
||||
skip,
|
||||
take,
|
||||
orderBy: [{ startDate: 'desc' }, { createdAt: 'desc' }],
|
||||
orderBy: [{ createdAt: 'desc' }],
|
||||
include: {
|
||||
customer: {
|
||||
select: {
|
||||
@@ -87,6 +88,7 @@ async function getAllContracts(filters) {
|
||||
},
|
||||
},
|
||||
address: true,
|
||||
billingAddress: true,
|
||||
salesPlatform: true,
|
||||
cancellationPeriod: true,
|
||||
contractDuration: true,
|
||||
@@ -108,6 +110,7 @@ async function getContractById(id, decryptPassword = false) {
|
||||
include: {
|
||||
customer: true,
|
||||
address: true,
|
||||
billingAddress: true,
|
||||
bankCard: true,
|
||||
identityDocument: true,
|
||||
salesPlatform: true,
|
||||
@@ -233,6 +236,7 @@ async function createContract(data) {
|
||||
include: {
|
||||
customer: true,
|
||||
address: true,
|
||||
billingAddress: true,
|
||||
salesPlatform: true,
|
||||
energyDetails: true,
|
||||
internetDetails: { include: { phoneNumbers: true } },
|
||||
@@ -598,4 +602,66 @@ async function getSipCredentials(phoneNumberId) {
|
||||
return { password: null };
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Verträge eines Kunden als Baumstruktur abrufen.
|
||||
* Wurzelknoten = Verträge ohne Nachfolger (aktuellste Verträge)
|
||||
* Vorgänger werden rekursiv eingebettet.
|
||||
*/
|
||||
async function getContractTreeForCustomer(customerId) {
|
||||
// Alle Verträge des Kunden laden (außer DEACTIVATED)
|
||||
const allContracts = await prisma.contract.findMany({
|
||||
where: {
|
||||
customerId,
|
||||
status: { not: client_1.ContractStatus.DEACTIVATED },
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
contractNumber: true,
|
||||
type: true,
|
||||
status: true,
|
||||
startDate: true,
|
||||
endDate: true,
|
||||
providerName: true,
|
||||
tariffName: true,
|
||||
previousContractId: true,
|
||||
provider: { select: { id: true, name: true } },
|
||||
tariff: { select: { id: true, name: true } },
|
||||
contractCategory: { select: { id: true, name: true } },
|
||||
},
|
||||
orderBy: [{ startDate: 'desc' }, { createdAt: 'desc' }],
|
||||
});
|
||||
// Map für schnellen Zugriff: contractId -> contract
|
||||
const contractMap = new Map(allContracts.map(c => [c.id, c]));
|
||||
// Set der IDs die als Vorgänger referenziert werden
|
||||
const predecessorIds = new Set(allContracts
|
||||
.filter(c => c.previousContractId !== null)
|
||||
.map(c => c.previousContractId));
|
||||
// Wurzelverträge = Verträge die keinen Nachfolger haben
|
||||
// (werden von keinem anderen Vertrag als previousContractId referenziert)
|
||||
const rootContracts = allContracts.filter(c => !predecessorIds.has(c.id));
|
||||
// Rekursive Funktion um Vorgängerkette aufzubauen
|
||||
function buildPredecessorChain(contractId) {
|
||||
if (contractId === null)
|
||||
return [];
|
||||
const contract = contractMap.get(contractId);
|
||||
if (!contract)
|
||||
return [];
|
||||
const predecessors = buildPredecessorChain(contract.previousContractId);
|
||||
return [{
|
||||
contract,
|
||||
predecessors,
|
||||
hasHistory: predecessors.length > 0,
|
||||
}];
|
||||
}
|
||||
// Baumstruktur für jeden Wurzelvertrag aufbauen
|
||||
const tree = rootContracts.map(contract => {
|
||||
const predecessors = buildPredecessorChain(contract.previousContractId);
|
||||
return {
|
||||
contract,
|
||||
predecessors,
|
||||
hasHistory: predecessors.length > 0,
|
||||
};
|
||||
});
|
||||
return tree;
|
||||
}
|
||||
//# sourceMappingURL=contract.service.js.map
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+1
@@ -173,6 +173,7 @@ export declare function getCustomerById(id: number): Promise<({
|
||||
contractNumber: string;
|
||||
contractCategoryId: number | null;
|
||||
addressId: number | null;
|
||||
billingAddressId: number | null;
|
||||
bankCardId: number | null;
|
||||
identityDocumentId: number | null;
|
||||
salesPlatformId: number | null;
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user