remove filterUserDefaultTagResponse + fix defaultTagTask
MODIFY
src/migration/tasks/SetDefaultTagToUserTask.ts
src/migration/tasks/SetDefaultTagToUserTask.ts
@@ -21,19 +21,21 @@ export default class SetDefaultTagToUserTask extends MigrationTask {
let modifiedCount = 0;
const users = await UserStorage.getUsers(tenant.id, {
issuer: true,
- withTag: true
}, Constants.DB_PARAMS_MAX_LIMIT);
if (users.count > 0) {
for (const user of users.result) {
- if (user.tags.length === 1 && !user.tags[0].default) {
- await global.database.getCollection<any>(tenant.id, 'tags').findOneAndUpdate(
- { '_id': user.tags[0].id },
- { $set: { 'default': true } }
- );
+ const tagsMDB = await UserStorage.getTags(tenant.id, {
+ userIDs: [user.id]
+ }, Constants.DB_PARAMS_SINGLE_RECORD);
+ if (tagsMDB.count === 1) {
+ if (!tagsMDB.result[0].default) {
+ tagsMDB.result[0].default = true;
+ await UserStorage.saveTag(tenant.id, tagsMDB.result[0]);
modifiedCount++;
}
}
}
+ }
// Log in the default tenant
if (modifiedCount > 0) {
Logging.logDebug({

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -1069,23 +1069,33 @@ export default class UserService {
userIDs: [userID],
defaultTag: true,
active: true
- }, Constants.DB_PARAMS_SINGLE_RECORD);
+ }, Constants.DB_PARAMS_SINGLE_RECORD, [
+ 'id', 'userID', 'active', 'ocpiToken', 'description', 'issuer', 'default'
+ ]);
if (tagsMDB.count < 1) {
tagsMDB = await UserStorage.getTags(req.user.tenantID, {
userIDs: [userID],
active: true
- }, Constants.DB_PARAMS_SINGLE_RECORD);
+ }, Constants.DB_PARAMS_SINGLE_RECORD,[
+ 'id', 'userID', 'active', 'ocpiToken', 'description', 'issuer', 'default'
+ ]);
}
const tag = tagsMDB.count > 0 ? tagsMDB.result[0] : null;
let carsMDB = await CarStorage.getCars(req.user.tenantID,
{ userIDs: [userID], defaultCar: true },
- Constants.DB_PARAMS_SINGLE_RECORD);
+ Constants.DB_PARAMS_SINGLE_RECORD,[
+ 'id', 'type', 'vin', 'licensePlate', 'converter', 'default', 'owner', 'createdOn', 'lastChangedOn',
+ 'carCatalog.vehicleMake', 'carCatalog.vehicleModel', 'carCatalog.vehicleModelVersion',
+ ]);
carsMDB = carsMDB.count > 0 ? carsMDB : await CarStorage.getCars(req.user.tenantID,
{ userIDs: [userID] },
- Constants.DB_PARAMS_SINGLE_RECORD);
+ Constants.DB_PARAMS_SINGLE_RECORD,[
+ 'id', 'type', 'vin', 'licensePlate', 'converter', 'default', 'owner', 'createdOn', 'lastChangedOn',
+ 'carCatalog.vehicleMake', 'carCatalog.vehicleModel', 'carCatalog.vehicleModelVersion',
+ ]);
const car = carsMDB.count > 0 ? carsMDB.result[0] : null;
// Return
- res.json(UserSecurity.filterUserDefaultTagResponse(tag, car, req.user));
+ res.json({ tag, car });
next();
}

remove filterUserDefaultTagResponse + fix defaultTagTask