Import functionallity for testing
MODIFY
package.json
package.json
"xmake:download-node-headers": "wget https://nexus.wdf.sap.corp:8443/nexus/service/local/repositories/3rd-party.releases.manual-uploads.hosted/content/org/nodejs/download/node/node-headers/12.13.0/node-headers-12.13.0.tar.gz -P ${WORKSPACE}/gen/tmp/"
},
"dependencies": {
+ "JSONStream": "^1.3.5",
"ajv": "^6.12.6",
"ajv-sanitizer": "^1.1.4",
"axios": "^0.21.1",

MODIFY
src/server/rest/CentralRestServerService.ts
src/server/rest/CentralRestServerService.ts
@@ -101,6 +101,7 @@ class RequestMapper {
[ServerAction.CAR_CREATE]: CarService.handleCreateCar.bind(this),
[ServerAction.TAG_CREATE]: TagService.handleCreateTag.bind(this),
[ServerAction.END_USER_REPORT_ERROR]: NotificationService.handleEndUserReportError.bind(this),
+ [ServerAction.USERS_IMPORT]: UserService.import.bind(this),
});
break;

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -17,10 +17,12 @@ import Cypher from '../../../../utils/Cypher';
import { DataResult } from '../../../../types/DataResult';
import EmspOCPIClient from '../../../../client/ocpi/EmspOCPIClient';
import I18nManager from '../../../../utils/I18nManager';
+import JSONStream from 'JSONStream';
import Logging from '../../../../utils/Logging';
import NotificationHandler from '../../../../notification/NotificationHandler';
import OCPIClientFactory from '../../../../client/ocpi/OCPIClientFactory';
import { OCPIRole } from '../../../../types/ocpi/OCPIRole';
+import { Readable } from 'stream';
import { ServerAction } from '../../../../types/Server';
import SettingStorage from '../../../../storage/mongodb/SettingStorage';
import SiteStorage from '../../../../storage/mongodb/SiteStorage';
@@ -103,6 +105,21 @@ export default class UserService {
next();
}
+ public static async import(action: ServerAction, req: Request, res: Response, next: NextFunction) {
+
+ const stream = Readable.from(req); // Rows, ANYTHING, doc
+
+ stream.on('data', function(body) {
+ console.log(
+ body.toString());
+ // UserStorage.saveImportedUser(req.user.tenantID, JSON.parse(body.toString().substring(body.indexOf('['), body.indexOf(']') + 1)));
+ });
+
+ console.log(req.body);
+
+ res.send('success');
+ }
+
public static async handleAssignSitesToUser(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.ORGANIZATION,
Action.UPDATE, Entity.SITES, 'SiteService', 'handleAssignSitesToUser');

MODIFY
src/storage/mongodb/UserStorage.ts
src/storage/mongodb/UserStorage.ts
@@ -270,6 +270,12 @@ export default class UserStorage {
return userMDB._id.toHexString();
}
+ public static saveImportedUser(tenantID: string, usersToSave): void {
+ void global.database.getCollection<any>(tenantID, 'userImport2').insertMany(
+ usersToSave);
+ console.log('saved:', usersToSave);
+ }
+
public static async saveUserPassword(tenantID: string, userID: string,
params: {
password?: string; passwordResetHash?: string; passwordWrongNbrTrials?: number;

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -352,6 +352,7 @@ export enum ServerAction {
TAGS_DELETE = 'TagsDelete',
USER = 'User',
USERS_EXPORT = 'UsersExport',
+ USERS_IMPORT = 'UsersImport',
NOTIFICATIONS = 'Notifications',

Import functionallity for testing