From b7c4ee71c3ee57dc7940cc94043db78de289f7b4 Mon Sep 17 00:00:00 2001 From: Dovile Date: Tue, 23 Apr 2024 13:54:52 +0300 Subject: [PATCH 1/4] prevent tenant name update if name is invalid --- services/auth.service.ts | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/services/auth.service.ts b/services/auth.service.ts index 0b5affb..4cc3548 100644 --- a/services/auth.service.ts +++ b/services/auth.service.ts @@ -85,6 +85,8 @@ export default class AuthService extends moleculer.Service { meta, }); + console.log('afterUserLoggedIn authUser', authUser); + if (authUser?.type !== UserType.USER) { if (process.env.NODE_ENV === 'local') { return data; @@ -99,6 +101,8 @@ export default class AuthService extends moleculer.Service { }, }); + console.log('afterUserLoggedIn user', user); + if (!user) { // Should not be a case. But sometimes it happens user = await ctx.call('users.create', { @@ -119,6 +123,9 @@ export default class AuthService extends moleculer.Service { }, { meta }, ); + + console.log('afterUserLoggedIn authUserGroups', authUserGroups); + const authGroups: any[] = authUserGroups?.groups || []; const isFreelancer = authGroups.some( @@ -126,7 +133,7 @@ export default class AuthService extends moleculer.Service { ); // update user info from e-vartai - await ctx.call('users.update', { + const updatedUser = await ctx.call('users.update', { id: user.id, firstName: authUser.firstName, lastName: authUser.lastName, @@ -134,6 +141,9 @@ export default class AuthService extends moleculer.Service { isFreelancer, }); + console.log('afterUserLoggedIn updatedUser', updatedUser); + + let i = 0; for (const authGroup of authGroups) { if (!authGroup.id) { continue; @@ -145,18 +155,27 @@ export default class AuthService extends moleculer.Service { }, }); + console.log('afterUserLoggedIn tenant ' + 1, tenant); + if (!tenant) { continue; } - await ctx.call('tenants.update', { + let name = tenant.name; + if (authGroup.name && !(authGroup.name as string).startsWith('Company: ')) { + name = authGroup.name; + } + + const updatedTenant = await ctx.call('tenants.update', { id: tenant.id, - name: authGroup.name, + name, code: authGroup.companyCode, email: authGroup.companyEmail, phone: authGroup.companyPhone, }); + console.log('afterUserLoggedIn updatedTenant ' + i, updatedTenant); + // Update tenantUser role if changed in Auth module // Should only be a case when NOT OWNER becomes an OWNER (after login as "juridinis asmuo") // All other cases are done from our app and synced to Auth From b2dbf98c17999a8a1ff85cbb82240330b8733551 Mon Sep 17 00:00:00 2001 From: Dovile Date: Tue, 23 Apr 2024 14:06:07 +0300 Subject: [PATCH 2/4] console.logs deleted --- services/auth.service.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/services/auth.service.ts b/services/auth.service.ts index 4cc3548..6c24351 100644 --- a/services/auth.service.ts +++ b/services/auth.service.ts @@ -85,8 +85,6 @@ export default class AuthService extends moleculer.Service { meta, }); - console.log('afterUserLoggedIn authUser', authUser); - if (authUser?.type !== UserType.USER) { if (process.env.NODE_ENV === 'local') { return data; @@ -101,8 +99,6 @@ export default class AuthService extends moleculer.Service { }, }); - console.log('afterUserLoggedIn user', user); - if (!user) { // Should not be a case. But sometimes it happens user = await ctx.call('users.create', { @@ -124,8 +120,6 @@ export default class AuthService extends moleculer.Service { { meta }, ); - console.log('afterUserLoggedIn authUserGroups', authUserGroups); - const authGroups: any[] = authUserGroups?.groups || []; const isFreelancer = authGroups.some( @@ -141,8 +135,6 @@ export default class AuthService extends moleculer.Service { isFreelancer, }); - console.log('afterUserLoggedIn updatedUser', updatedUser); - let i = 0; for (const authGroup of authGroups) { if (!authGroup.id) { @@ -155,8 +147,6 @@ export default class AuthService extends moleculer.Service { }, }); - console.log('afterUserLoggedIn tenant ' + 1, tenant); - if (!tenant) { continue; } @@ -174,8 +164,6 @@ export default class AuthService extends moleculer.Service { phone: authGroup.companyPhone, }); - console.log('afterUserLoggedIn updatedTenant ' + i, updatedTenant); - // Update tenantUser role if changed in Auth module // Should only be a case when NOT OWNER becomes an OWNER (after login as "juridinis asmuo") // All other cases are done from our app and synced to Auth From 91bd423832fe044b0a831453e6216006a4c827f2 Mon Sep 17 00:00:00 2001 From: Dovile Date: Tue, 23 Apr 2024 14:06:56 +0300 Subject: [PATCH 3/4] unnecessary code deleted --- services/auth.service.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/services/auth.service.ts b/services/auth.service.ts index 6c24351..d979767 100644 --- a/services/auth.service.ts +++ b/services/auth.service.ts @@ -135,7 +135,6 @@ export default class AuthService extends moleculer.Service { isFreelancer, }); - let i = 0; for (const authGroup of authGroups) { if (!authGroup.id) { continue; From e4dec4b56bfc19061976c30e862c14248c952a36 Mon Sep 17 00:00:00 2001 From: Dovile Date: Tue, 23 Apr 2024 14:08:14 +0300 Subject: [PATCH 4/4] unnecessary code deleted --- services/auth.service.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/services/auth.service.ts b/services/auth.service.ts index d979767..cd8c11d 100644 --- a/services/auth.service.ts +++ b/services/auth.service.ts @@ -119,7 +119,6 @@ export default class AuthService extends moleculer.Service { }, { meta }, ); - const authGroups: any[] = authUserGroups?.groups || []; const isFreelancer = authGroups.some( @@ -127,7 +126,7 @@ export default class AuthService extends moleculer.Service { ); // update user info from e-vartai - const updatedUser = await ctx.call('users.update', { + await ctx.call('users.update', { id: user.id, firstName: authUser.firstName, lastName: authUser.lastName, @@ -155,7 +154,7 @@ export default class AuthService extends moleculer.Service { name = authGroup.name; } - const updatedTenant = await ctx.call('tenants.update', { + await ctx.call('tenants.update', { id: tenant.id, name, code: authGroup.companyCode,