Skip to content

Commit 9470e79

Browse files
author
dzzzzzy
committedJan 24, 2019
refactor(service): change forEach to forof
1 parent c85f89e commit 9470e79

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed
 

‎src/services/resource.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class ResourceService {
4242
// Sacnned resources
4343
for (const [key, value] of metadataMap) {
4444
const resourceModule = await this.systemModuleRepo.findOne({ where: { name: value.name } });
45-
value.resource.forEach(async resouece => {
45+
value.resource.forEach(resouece => {
4646
resouece.systemModule = resourceModule;
4747
});
4848
}

‎src/services/user.service.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,16 @@ export class UserService {
189189
await this.userRepo.update(user.id, { recycle: updateUserInput.recycle });
190190
}
191191
if (updateUserInput.roleIds && updateUserInput.roleIds.length) {
192-
updateUserInput.roleIds.forEach(async roleId => {
192+
for (const roleId of updateUserInput.roleIds) {
193193
await this.userRepo.createQueryBuilder('user').relation(User, 'roles').of(user).remove(roleId.before);
194194
await this.userRepo.createQueryBuilder('user').relation(User, 'roles').of(user).add(roleId.after);
195-
});
195+
}
196196
}
197197
if (updateUserInput.organizationIds && updateUserInput.organizationIds.length) {
198-
updateUserInput.organizationIds.forEach(async organizationId => {
198+
for (const organizationId of updateUserInput.organizationIds) {
199199
await this.userRepo.createQueryBuilder('user').relation(User, 'organizations').of(user).remove(organizationId.before);
200200
await this.userRepo.createQueryBuilder('user').relation(User, 'organizations').of(user).add(organizationId.after);
201-
});
201+
}
202202
}
203203
if (updateUserInput.infoKVs && updateUserInput.infoKVs.length) {
204204
await this.createOrUpdateUserInfos(user, updateUserInput.infoKVs, 'update');
@@ -445,21 +445,21 @@ export class UserService {
445445
private async createOrUpdateUserInfos(user: User, infoKVs: CreateUserInfoKVs[] | UpdateUserInfoKVs[], action: 'create' | 'update') {
446446
if (infoKVs.length) {
447447
if (action === 'create') {
448-
(infoKVs as CreateUserInfoKVs[]).forEach(async infoKV => {
448+
for (const infoKV of (infoKVs as CreateUserInfoKVs[])) {
449449
const userInfo = this.userInfoRepo.create({ value: infoKV.userInfoValue, user, infoItem: { id: infoKV.infoItemId } });
450450
await this.userInfoRepo.save(userInfo);
451-
});
451+
}
452452
return;
453453
}
454454

455-
(infoKVs as UpdateUserInfoKVs[]).forEach(async infoKV => {
455+
for (const infoKV of (infoKVs as UpdateUserInfoKVs[])) {
456456
if (infoKV.userInfoId) {
457457
await this.userInfoRepo.update(infoKV.userInfoId, { value: infoKV.userInfoValue });
458458
} else {
459459
const userInfo = this.userInfoRepo.create({ value: infoKV.userInfoValue, user, infoItem: { id: infoKV.infoItemId } });
460460
await this.userInfoRepo.save(userInfo);
461461
}
462-
});
462+
}
463463
}
464464
}
465465

0 commit comments

Comments
 (0)
Please sign in to comment.