billing - remove deprecated method
MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -1101,128 +1101,6 @@ export default class UserService {
next();
}
- public static async handleGetUserInvoice(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
- // Filter
- const id = UserSecurity.filterUserByIDRequest(req.query);
- // User mandatory
- if (!id) {
- throw new AppError({
- source: Constants.CENTRAL_SERVER,
- errorCode: HTTPError.GENERAL_ERROR,
- message: 'User\'s ID must be provided',
- module: MODULE_NAME, method: 'handleGetUserInvoice',
- user: req.user,
- action: action
- });
- }
- // Check auth
- if (!await Authorizations.canReadUser(req.user)) {
- throw new AppAuthError({
- errorCode: HTTPAuthError.FORBIDDEN,
- user: req.user,
- action: Action.READ, entity: Entity.USER,
- module: MODULE_NAME, method: 'handleGetUserInvoice',
- value: id
- });
- }
- // Get authorization filters
- const authorizationUserFilters = await AuthorizationService.checkAndGetUserAuthorizationFilters(
- req.tenant, req.user, { ID: id });
- // Get the user
- const user = await UserStorage.getUser(req.user.tenantID, id, authorizationUserFilters.filters);
- UtilsService.assertObjectExists(action, user, `User ID '${id}' does not exist`,
- MODULE_NAME, 'handleGetUserInvoice', req.user);
- // Get the settings
- const pricingSetting = await SettingStorage.getPricingSettings(req.user.tenantID);
- if (!pricingSetting || !pricingSetting.convergentCharging) {
- await Logging.logException(
- new Error('Convergent Charging setting is missing'),
- action, Constants.CENTRAL_SERVER, MODULE_NAME, 'handleGetUserInvoice', req.user.tenantID, req.user);
- throw new AppError({
- source: Constants.CENTRAL_SERVER,
- errorCode: HTTPError.GENERAL_ERROR,
- action: action,
- module: MODULE_NAME, method: 'handleGetUserInvoice',
- user: req.user,
- message: 'An issue occurred while creating the invoice',
- });
- }
- // Create services
- // FIXME: The calls to external pricing services need to be integrated inside the pricing integration interface definition, see https://github.com/sap-labs-france/ev-dashboard/issues/1542
- // const ratingService = ConvergentChargingPricingIntegration.getRatingServiceClient(pricingSetting.convergentCharging.url, pricingSetting.convergentCharging.user, pricingSetting.convergentCharging.password);
- // const erpService = ConvergentChargingPricingIntegration.getERPServiceClient(pricingSetting.convergentCharging.url, pricingSetting.convergentCharging.user, pricingSetting.convergentCharging.password);
- let invoiceNumber: string;
- try {
- // pragma await ratingService.loadChargedItemsToInvoicing();
- // invoiceNumber = await erpService.createInvoice(req.user.tenantID, user);
- } catch (error) {
- throw new AppError({
- source: Constants.CENTRAL_SERVER,
- errorCode: HTTPError.GENERAL_ERROR,
- message: 'An issue occurred while creating the invoice',
- module: MODULE_NAME, method: 'handleGetUserInvoice',
- user: req.user,
- action: action,
- detailedMessages: { error: error.message, stack: error.stack }
- });
- }
- if (!invoiceNumber) {
- throw new AppError({
- source: Constants.CENTRAL_SERVER,
- errorCode: StatusCodes.NOT_FOUND,
- message: 'No invoices available',
- module: MODULE_NAME, method: 'handleGetUserInvoice',
- user: req.user,
- action: action
- });
- }
- let invoice;
- try {
- // pragma const invoiceHeader = await erpService.getInvoiceDocumentHeader(invoiceNumber);
- // invoice = await erpService.getInvoiceDocument(invoiceHeader, invoiceNumber);
- if (!invoice) {
- // Retry to get invoice
- // invoice = await erpService.getInvoiceDocument(invoiceHeader, invoiceNumber);
- }
- if (!invoice) {
- throw new AppError({
- source: Constants.CENTRAL_SERVER,
- errorCode: HTTPError.PRICING_REQUEST_INVOICE_ERROR,
- message: `An error occurred while requesting invoice ${invoiceNumber}`,
- module: MODULE_NAME, method: 'handleGetUserInvoice',
- user: req.user,
- action: action
- });
- }
- const filename = 'invoice.pdf';
- fs.writeFile(filename, invoice, (err) => {
- if (err) {
- throw err;
- }
- res.download(filename, (err2) => {
- if (err2) {
- throw err2;
- }
- fs.unlink(filename, (err3) => {
- if (err3) {
- throw err3;
- }
- });
- });
- });
- } catch (error) {
- throw new AppError({
- source: Constants.CENTRAL_SERVER,
- errorCode: HTTPError.PRICING_REQUEST_INVOICE_ERROR,
- message: `An error occurred while requesting invoice ${invoiceNumber}`,
- module: MODULE_NAME, method: 'handleGetUserInvoice',
- user: req.user,
- action: action,
- detailedMessages: { error: error.message, stack: error.stack }
- });
- }
- }
-
private static async insertUsers(tenantID: string, user: UserToken, action: ServerAction, usersToBeImported: ImportedUser[], result: ActionsResponse): Promise<void> {
try {
const nbrInsertedUsers = await UserStorage.saveImportedUsers(tenantID, usersToBeImported);

billing - remove deprecated method