@things-factory/biz-base 7.0.0-alpha.9 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-server/index.d.ts +3 -0
- package/dist-server/middlewares/index.d.ts +0 -0
- package/dist-server/migrations/index.d.ts +1 -0
- package/dist-server/service/biz-option/biz-option-mutation.d.ts +8 -0
- package/dist-server/service/biz-option/biz-option-mutation.js +2 -2
- package/dist-server/service/biz-option/biz-option-mutation.js.map +1 -1
- package/dist-server/service/biz-option/biz-option-query.d.ts +7 -0
- package/dist-server/service/biz-option/biz-option-query.js +3 -3
- package/dist-server/service/biz-option/biz-option-query.js.map +1 -1
- package/dist-server/service/biz-option/biz-option-types.d.ts +18 -0
- package/dist-server/service/biz-option/biz-option-types.js +6 -6
- package/dist-server/service/biz-option/biz-option-types.js.map +1 -1
- package/dist-server/service/biz-option/biz-option.d.ts +16 -0
- package/dist-server/service/biz-option/biz-option.js +2 -2
- package/dist-server/service/biz-option/biz-option.js.map +1 -1
- package/dist-server/service/biz-option/index.d.ts +5 -0
- package/dist-server/service/biz-option-detail/biz-option-detail-mutation.d.ts +8 -0
- package/dist-server/service/biz-option-detail/biz-option-detail-mutation.js +2 -2
- package/dist-server/service/biz-option-detail/biz-option-detail-mutation.js.map +1 -1
- package/dist-server/service/biz-option-detail/biz-option-detail-query.d.ts +7 -0
- package/dist-server/service/biz-option-detail/biz-option-detail-query.js +3 -3
- package/dist-server/service/biz-option-detail/biz-option-detail-query.js.map +1 -1
- package/dist-server/service/biz-option-detail/biz-option-detail-types.d.ts +16 -0
- package/dist-server/service/biz-option-detail/biz-option-detail-types.js +6 -6
- package/dist-server/service/biz-option-detail/biz-option-detail-types.js.map +1 -1
- package/dist-server/service/biz-option-detail/biz-option-detail.d.ts +14 -0
- package/dist-server/service/biz-option-detail/biz-option-detail.js +2 -2
- package/dist-server/service/biz-option-detail/biz-option-detail.js.map +1 -1
- package/dist-server/service/biz-option-detail/index.d.ts +5 -0
- package/dist-server/service/bizplace/bizplace-mutation.d.ts +10 -0
- package/dist-server/service/bizplace/bizplace-mutation.js +2 -2
- package/dist-server/service/bizplace/bizplace-mutation.js.map +1 -1
- package/dist-server/service/bizplace/bizplace-query.d.ts +19 -0
- package/dist-server/service/bizplace/bizplace-query.js +8 -8
- package/dist-server/service/bizplace/bizplace-query.js.map +1 -1
- package/dist-server/service/bizplace/bizplace-types.d.ts +34 -0
- package/dist-server/service/bizplace/bizplace-types.js +8 -8
- package/dist-server/service/bizplace/bizplace-types.js.map +1 -1
- package/dist-server/service/bizplace/bizplace.d.ts +22 -0
- package/dist-server/service/bizplace/bizplace.js +3 -3
- package/dist-server/service/bizplace/bizplace.js.map +1 -1
- package/dist-server/service/bizplace/index.d.ts +5 -0
- package/dist-server/service/company/company-mutation.d.ts +48 -0
- package/dist-server/service/company/company-mutation.js +7 -7
- package/dist-server/service/company/company-mutation.js.map +1 -1
- package/dist-server/service/company/company-query.d.ts +11 -0
- package/dist-server/service/company/company-query.js +3 -3
- package/dist-server/service/company/company-query.js.map +1 -1
- package/dist-server/service/company/company-types.d.ts +26 -0
- package/dist-server/service/company/company-types.js +6 -6
- package/dist-server/service/company/company-types.js.map +1 -1
- package/dist-server/service/company/company.d.ts +23 -0
- package/dist-server/service/company/company.js +2 -2
- package/dist-server/service/company/company.js.map +1 -1
- package/dist-server/service/company/index.d.ts +5 -0
- package/dist-server/service/contact-point/contact-point-mutation.d.ts +13 -0
- package/dist-server/service/contact-point/contact-point-mutation.js +6 -6
- package/dist-server/service/contact-point/contact-point-mutation.js.map +1 -1
- package/dist-server/service/contact-point/contact-point-query.d.ts +7 -0
- package/dist-server/service/contact-point/contact-point-query.js +3 -3
- package/dist-server/service/contact-point/contact-point-query.js.map +1 -1
- package/dist-server/service/contact-point/contact-point-types.d.ts +54 -0
- package/dist-server/service/contact-point/contact-point-types.js +14 -6
- package/dist-server/service/contact-point/contact-point-types.js.map +1 -1
- package/dist-server/service/contact-point/contact-point.d.ts +32 -0
- package/dist-server/service/contact-point/contact-point.js +9 -7
- package/dist-server/service/contact-point/contact-point.js.map +1 -1
- package/dist-server/service/contact-point/index.d.ts +5 -0
- package/dist-server/service/index.d.ts +18 -0
- package/dist-server/service/worker/index.d.ts +5 -0
- package/dist-server/service/worker/worker-mutation.d.ts +37 -0
- package/dist-server/service/worker/worker-mutation.js +7 -7
- package/dist-server/service/worker/worker-mutation.js.map +1 -1
- package/dist-server/service/worker/worker-query.d.ts +7 -0
- package/dist-server/service/worker/worker-query.js +3 -3
- package/dist-server/service/worker/worker-query.js.map +1 -1
- package/dist-server/service/worker/worker-types.d.ts +20 -0
- package/dist-server/service/worker/worker-types.js +6 -6
- package/dist-server/service/worker/worker-types.js.map +1 -1
- package/dist-server/service/worker/worker.d.ts +15 -0
- package/dist-server/service/worker/worker.js +2 -2
- package/dist-server/service/worker/worker.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/dist-server/utils/get-permitted-bizplaces.d.ts +24 -0
- package/dist-server/utils/get-permitted-bizplaces.js +13 -14
- package/dist-server/utils/get-permitted-bizplaces.js.map +1 -1
- package/dist-server/utils/index.d.ts +1 -0
- package/package.json +3 -3
- package/server/service/biz-option/biz-option-query.ts +4 -1
- package/server/service/biz-option-detail/biz-option-detail-query.ts +1 -1
- package/server/service/bizplace/bizplace-query.ts +7 -4
- package/server/service/bizplace/bizplace.ts +2 -2
- package/server/service/company/company-query.ts +1 -1
- package/server/service/company/company.ts +1 -1
- package/server/service/contact-point/contact-point-query.ts +4 -1
- package/server/service/contact-point/contact-point-types.ts +6 -0
- package/server/service/contact-point/contact-point.ts +7 -10
- package/server/service/worker/worker-query.ts +1 -1
- package/server/service/worker/worker.ts +1 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { EntityManager } from 'typeorm';
|
|
2
|
+
import { User } from '@things-factory/auth-base';
|
|
3
|
+
import { Domain } from '@things-factory/shell';
|
|
4
|
+
import { Bizplace } from '../service/bizplace/bizplace';
|
|
5
|
+
/**
|
|
6
|
+
* @description 도메인과 사용자의 관계를 판단하여
|
|
7
|
+
* 접속한 도메인을 통해 접근 할 수 있는 대상 bizplaces를 찾아 return
|
|
8
|
+
*
|
|
9
|
+
* @param domain
|
|
10
|
+
* @param user
|
|
11
|
+
*/
|
|
12
|
+
export declare function getPermittedBizplaces(domain: Domain, user: User, tx?: EntityManager): Promise<Bizplace[]>;
|
|
13
|
+
export declare function getPermittedBizplaceIds(domain: Domain, user: User): Promise<string[] | any[]>;
|
|
14
|
+
export declare function getMyBizplace(domain: Domain, user: User, tx?: EntityManager): Promise<Bizplace>;
|
|
15
|
+
export declare function getOutletBizplace(outletId: string, tx?: EntityManager): Promise<Bizplace>;
|
|
16
|
+
export declare function getCompanyBizplace(domain: Domain, user: User, customerBizplaceId?: string, tx?: EntityManager): Promise<Bizplace>;
|
|
17
|
+
export declare function getCompaniesBizplaces(domains: Domain[], warehouseDomain: Domain, tx?: EntityManager): Promise<Bizplace[]>;
|
|
18
|
+
export declare function getPartnerBizplaceIds(domain: Domain, user: User, tx?: EntityManager): Promise<string[] | any[]>;
|
|
19
|
+
export declare function getPartnersBizplaces(domain: Domain, user: User, tx?: EntityManager): Promise<Bizplace[]>;
|
|
20
|
+
export declare function getPartnersCompanyBizplaces(domain: Domain, user: User, strictAccess?: Boolean, tx?: EntityManager): Promise<Bizplace[]>;
|
|
21
|
+
export declare function getCustomerBizplaces(domain: Domain, tx?: EntityManager): Promise<Bizplace[]>;
|
|
22
|
+
export declare function getSubdomainBizplace(subdomain: string, tx?: EntityManager): Promise<Bizplace>;
|
|
23
|
+
export declare function getUserBizplaces(user: User, tx?: EntityManager): Promise<Bizplace[]>;
|
|
24
|
+
export declare function getDomainUsers(bizplace: Bizplace, tx?: EntityManager): Promise<any[]>;
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getPermittedBizplaces = getPermittedBizplaces;
|
|
4
|
+
exports.getPermittedBizplaceIds = getPermittedBizplaceIds;
|
|
5
|
+
exports.getMyBizplace = getMyBizplace;
|
|
6
|
+
exports.getOutletBizplace = getOutletBizplace;
|
|
7
|
+
exports.getCompanyBizplace = getCompanyBizplace;
|
|
8
|
+
exports.getCompaniesBizplaces = getCompaniesBizplaces;
|
|
9
|
+
exports.getPartnerBizplaceIds = getPartnerBizplaceIds;
|
|
10
|
+
exports.getPartnersBizplaces = getPartnersBizplaces;
|
|
11
|
+
exports.getPartnersCompanyBizplaces = getPartnersCompanyBizplaces;
|
|
12
|
+
exports.getCustomerBizplaces = getCustomerBizplaces;
|
|
13
|
+
exports.getSubdomainBizplace = getSubdomainBizplace;
|
|
14
|
+
exports.getUserBizplaces = getUserBizplaces;
|
|
15
|
+
exports.getDomainUsers = getDomainUsers;
|
|
4
16
|
const typeorm_1 = require("typeorm");
|
|
5
17
|
const auth_base_1 = require("@things-factory/auth-base");
|
|
6
18
|
const shell_1 = require("@things-factory/shell");
|
|
@@ -31,12 +43,10 @@ async function getPermittedBizplaces(domain, user, tx) {
|
|
|
31
43
|
}
|
|
32
44
|
return permittedBizplaces;
|
|
33
45
|
}
|
|
34
|
-
exports.getPermittedBizplaces = getPermittedBizplaces;
|
|
35
46
|
async function getPermittedBizplaceIds(domain, user) {
|
|
36
47
|
const bizplaces = await getPermittedBizplaces(domain, user);
|
|
37
48
|
return bizplaces.map((bizplace) => bizplace.id || null);
|
|
38
49
|
}
|
|
39
|
-
exports.getPermittedBizplaceIds = getPermittedBizplaceIds;
|
|
40
50
|
async function getMyBizplace(domain, user, tx) {
|
|
41
51
|
const bizplaceRepo = tx ? tx.getRepository(bizplace_1.Bizplace) : (0, shell_1.getRepository)(bizplace_1.Bizplace);
|
|
42
52
|
// Case 1. 도메인에 소속된 사용자
|
|
@@ -59,7 +69,6 @@ async function getMyBizplace(domain, user, tx) {
|
|
|
59
69
|
});
|
|
60
70
|
}
|
|
61
71
|
}
|
|
62
|
-
exports.getMyBizplace = getMyBizplace;
|
|
63
72
|
async function getOutletBizplace(outletId, tx) {
|
|
64
73
|
const bizplaceRepo = tx ? tx.getRepository(bizplace_1.Bizplace) : (0, shell_1.getRepository)(bizplace_1.Bizplace);
|
|
65
74
|
const bizplace = await bizplaceRepo.findOne({
|
|
@@ -67,7 +76,6 @@ async function getOutletBizplace(outletId, tx) {
|
|
|
67
76
|
});
|
|
68
77
|
return bizplace;
|
|
69
78
|
}
|
|
70
|
-
exports.getOutletBizplace = getOutletBizplace;
|
|
71
79
|
async function getCompanyBizplace(domain, user, customerBizplaceId, tx) {
|
|
72
80
|
var _a, _b;
|
|
73
81
|
const bizplaceRepo = tx ? tx.getRepository(bizplace_1.Bizplace) : (0, shell_1.getRepository)(bizplace_1.Bizplace);
|
|
@@ -91,7 +99,6 @@ async function getCompanyBizplace(domain, user, customerBizplaceId, tx) {
|
|
|
91
99
|
}
|
|
92
100
|
return await bizplaceRepo.findOne({ where: { domain: { id: companyDomain.id } }, relations: ['domain'] });
|
|
93
101
|
}
|
|
94
|
-
exports.getCompanyBizplace = getCompanyBizplace;
|
|
95
102
|
async function getCompaniesBizplaces(domains, warehouseDomain, tx) {
|
|
96
103
|
const bizplaceRepo = tx ? tx.getRepository(bizplace_1.Bizplace) : (0, shell_1.getRepository)(bizplace_1.Bizplace);
|
|
97
104
|
const partnersBizplaces = await bizplaceRepo
|
|
@@ -111,7 +118,6 @@ async function getCompaniesBizplaces(domains, warehouseDomain, tx) {
|
|
|
111
118
|
.getRawMany();
|
|
112
119
|
return partnersBizplaces;
|
|
113
120
|
}
|
|
114
|
-
exports.getCompaniesBizplaces = getCompaniesBizplaces;
|
|
115
121
|
async function getPartnerBizplaceIds(domain, user, tx) {
|
|
116
122
|
const bizplaceRepo = tx ? tx.getRepository(bizplace_1.Bizplace) : (0, shell_1.getRepository)(bizplace_1.Bizplace);
|
|
117
123
|
const partnerRepo = tx ? tx.getRepository(auth_base_1.Partner) : (0, shell_1.getRepository)(auth_base_1.Partner);
|
|
@@ -130,7 +136,6 @@ async function getPartnerBizplaceIds(domain, user, tx) {
|
|
|
130
136
|
}
|
|
131
137
|
return partnerBizplaces.map((bizplace) => bizplace.id || null);
|
|
132
138
|
}
|
|
133
|
-
exports.getPartnerBizplaceIds = getPartnerBizplaceIds;
|
|
134
139
|
async function getPartnersBizplaces(domain, user, tx) {
|
|
135
140
|
const userRepo = tx ? tx.getRepository(auth_base_1.User) : (0, shell_1.getRepository)(auth_base_1.User);
|
|
136
141
|
const bizplaceRepo = tx ? tx.getRepository(bizplace_1.Bizplace) : (0, shell_1.getRepository)(bizplace_1.Bizplace);
|
|
@@ -181,7 +186,6 @@ async function getPartnersBizplaces(domain, user, tx) {
|
|
|
181
186
|
}
|
|
182
187
|
return partnersBizplaces;
|
|
183
188
|
}
|
|
184
|
-
exports.getPartnersBizplaces = getPartnersBizplaces;
|
|
185
189
|
async function getPartnersCompanyBizplaces(domain, user, strictAccess = false, tx) {
|
|
186
190
|
const userRepo = tx ? tx.getRepository(auth_base_1.User) : (0, shell_1.getRepository)(auth_base_1.User);
|
|
187
191
|
const bizplaceRepo = tx ? tx.getRepository(bizplace_1.Bizplace) : (0, shell_1.getRepository)(bizplace_1.Bizplace);
|
|
@@ -229,7 +233,6 @@ async function getPartnersCompanyBizplaces(domain, user, strictAccess = false, t
|
|
|
229
233
|
}
|
|
230
234
|
return partnersBizplaces;
|
|
231
235
|
}
|
|
232
|
-
exports.getPartnersCompanyBizplaces = getPartnersCompanyBizplaces;
|
|
233
236
|
async function getCustomerBizplaces(domain, tx) {
|
|
234
237
|
const partnerRepo = tx ? tx.getRepository(auth_base_1.Partner) : (0, shell_1.getRepository)(auth_base_1.Partner);
|
|
235
238
|
const bizplaceRepo = tx ? tx.getRepository(bizplace_1.Bizplace) : (0, shell_1.getRepository)(bizplace_1.Bizplace);
|
|
@@ -243,7 +246,6 @@ async function getCustomerBizplaces(domain, tx) {
|
|
|
243
246
|
relations: ['company', 'company.domain', 'domain']
|
|
244
247
|
});
|
|
245
248
|
}
|
|
246
|
-
exports.getCustomerBizplaces = getCustomerBizplaces;
|
|
247
249
|
async function getSubdomainBizplace(subdomain, tx) {
|
|
248
250
|
const domainRepo = tx ? tx.getRepository(shell_1.Domain) : (0, shell_1.getRepository)(shell_1.Domain);
|
|
249
251
|
const domain = await domainRepo.findOne({
|
|
@@ -251,7 +253,6 @@ async function getSubdomainBizplace(subdomain, tx) {
|
|
|
251
253
|
});
|
|
252
254
|
return await (0, shell_1.getRepository)(bizplace_1.Bizplace).findOne({ where: { domain: { id: domain.id } } });
|
|
253
255
|
}
|
|
254
|
-
exports.getSubdomainBizplace = getSubdomainBizplace;
|
|
255
256
|
async function getUserBizplaces(user, tx) {
|
|
256
257
|
var _a;
|
|
257
258
|
const userRepo = tx ? tx.getRepository(auth_base_1.User) : (0, shell_1.getRepository)(auth_base_1.User);
|
|
@@ -268,7 +269,6 @@ async function getUserBizplaces(user, tx) {
|
|
|
268
269
|
}
|
|
269
270
|
return userBizplaces.concat(await (0, shell_1.getRepository)(bizplace_1.Bizplace).find({ where: { domain: (0, typeorm_1.In)(userDomains.map((d) => d.id)) } }));
|
|
270
271
|
}
|
|
271
|
-
exports.getUserBizplaces = getUserBizplaces;
|
|
272
272
|
async function getDomainUsers(bizplace, tx) {
|
|
273
273
|
const userDomainRepo = tx ? tx.getRepository('users_domains') : (0, shell_1.getRepository)('users_domains');
|
|
274
274
|
const users = await userDomainRepo
|
|
@@ -287,5 +287,4 @@ async function getDomainUsers(bizplace, tx) {
|
|
|
287
287
|
.getRawMany();
|
|
288
288
|
return users;
|
|
289
289
|
}
|
|
290
|
-
exports.getDomainUsers = getDomainUsers;
|
|
291
290
|
//# sourceMappingURL=get-permitted-bizplaces.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-permitted-bizplaces.js","sourceRoot":"","sources":["../../server/utils/get-permitted-bizplaces.ts"],"names":[],"mappings":";;;A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C,GAAG,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CACpG,CAAA;AACH,CAAC;AAnBD,4CAmBC;AAEM,KAAK,UAAU,cAAc,CAAC,QAAkB,EAAE,EAAkB;IACzE,MAAM,cAAc,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,IAAA,qBAAa,EAAC,eAAe,CAAC,CAAA;IAE9F,MAAM,KAAK,GAAU,MAAM,cAAc;SACtC,kBAAkB,CAAC,IAAI,CAAC;SACxB,MAAM,CAAC,aAAa,EAAE,IAAI,CAAC;SAC3B,QAAQ,CAAC,IAAI,CAAC;SACd,KAAK,CAAC,EAAE,CAAC,EAAE;QACV,MAAM,QAAQ,GAAG,EAAE;aAChB,QAAQ,EAAE;aACV,MAAM,CAAC,oBAAoB,CAAC;aAC5B,IAAI,CAAC,mBAAQ,EAAE,UAAU,CAAC;aAC1B,KAAK,CAAC,mCAAmC,EAAE,EAAE,kBAAkB,EAAE,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,EAAE,EAAE,CAAC;aAChF,QAAQ,EAAE,CAAA;QACb,OAAO,kBAAkB,GAAG,QAAQ,CAAA;IACtC,CAAC,CAAC;SACD,UAAU,EAAE,CAAA;IAEf,OAAO,KAAK,CAAA;AACd,CAAC;AAnBD,wCAmBC","sourcesContent":["import { EntityManager, In, SelectQueryBuilder } from 'typeorm'\n\nimport { checkUserBelongsDomain, Partner, User } from '@things-factory/auth-base'\nimport { Domain, getRepository } from '@things-factory/shell'\n\nimport { Bizplace } from '../service/bizplace/bizplace'\n\n/**\n * @description 도메인과 사용자의 관계를 판단하여\n * 접속한 도메인을 통해 접근 할 수 있는 대상 bizplaces를 찾아 return\n *\n * @param domain\n * @param user\n */\nexport async function getPermittedBizplaces(domain: Domain, user: User, tx?: EntityManager): Promise<Bizplace[]> {\n const bizplaceRepo = tx ? tx.getRepository(Bizplace) : getRepository(Bizplace)\n\n // 1. Check whether `user` belongs to `domain` or not\n let permittedBizplaces: Bizplace[] = []\n if (await checkUserBelongsDomain(domain, user)) {\n // If `user` belongs to `domain`\n // return set of company bizplace, bizplace of passed domain, bizplaces of customers\n\n if (domain.extType !== 'company') permittedBizplaces.push(await getCompanyBizplace(domain, user, null, tx))\n permittedBizplaces.push(await bizplaceRepo.findOne({ where: { domain: { id: domain.id } } }))\n permittedBizplaces = permittedBizplaces.concat(await getCustomerBizplaces(domain, tx))\n } else {\n // If `user` doesn't belong to `domain`\n // return set of company bizplace, bizplaces which `user` can access\n permittedBizplaces = await getUserBizplaces(user)\n }\n\n return permittedBizplaces\n}\n\nexport async function getPermittedBizplaceIds(domain: Domain, user: User): Promise<string[] | any[]> {\n const bizplaces: Bizplace[] = await getPermittedBizplaces(domain, user)\n return bizplaces.map((bizplace: Bizplace) => bizplace.id || null)\n}\n\nexport async function getMyBizplace(domain: Domain, user: User, tx?: EntityManager): Promise<Bizplace> {\n const bizplaceRepo = tx ? tx.getRepository(Bizplace) : getRepository(Bizplace)\n\n // Case 1. 도메인에 소속된 사용자\n // 1. 현재 도메인을 릴레이션으로 가지고 있는 비즈플레이스를 리턴\n\n if (await checkUserBelongsDomain(domain, user)) {\n return await bizplaceRepo.findOne({ where: { domain: { id: domain.id } } })\n } else {\n const customerBizplaces: Bizplace[] = await getCustomerBizplaces(domain, tx)\n const userBizplaces: Bizplace[] = await getUserBizplaces(user, tx)\n\n const customerBizplaceIdSet: Set<string> = new Set(customerBizplaces.map((pb: Bizplace) => pb.id))\n const userBizplaceIdSet: Set<string> = new Set(userBizplaces.map((ub: Bizplace) => ub.id))\n\n const myBizplaceIds: string[] = Array.from(customerBizplaceIdSet).filter((pbId: string) =>\n userBizplaceIdSet.has(pbId)\n )\n if (myBizplaceIds.length > 1) console.warn(`User has multiple bizplaces ${myBizplaceIds}`)\n\n // TODO: 복수의 비즈플레이스를 가지고 있는 사용자는 조회 결과의 첫번째 비즈플레이스만 리턴 받도록 되어 있음\n // 이런 케이스에 처리 방식을 결정하고 수정해야함\n return await bizplaceRepo.findOne({\n where: { id: In(myBizplaceIds) }\n })\n }\n}\n\nexport async function getOutletBizplace(outletId: string, tx?: EntityManager) {\n const bizplaceRepo = tx ? tx.getRepository(Bizplace) : getRepository(Bizplace)\n\n const bizplace: Bizplace = await bizplaceRepo.findOne({\n where: { id: outletId }\n })\n return bizplace\n}\n\nexport async function getCompanyBizplace(\n domain: Domain,\n user: User,\n customerBizplaceId?: string,\n tx?: EntityManager\n): Promise<Bizplace> {\n const bizplaceRepo = tx ? tx.getRepository(Bizplace) : getRepository(Bizplace)\n\n let companyDomain: Domain\n\n if (user) {\n let myBizplace: Bizplace = await getMyBizplace(domain, user, tx)\n if (!myBizplace.company?.id) {\n myBizplace = await bizplaceRepo.findOne({\n where: { id: myBizplace.id },\n relations: ['company', 'company.domain']\n })\n companyDomain = myBizplace.company.domain\n }\n }\n\n if (customerBizplaceId) {\n const customerBizplace: Bizplace = await bizplaceRepo.findOne({\n where: { id: customerBizplaceId },\n relations: ['company', 'company.domain']\n })\n\n companyDomain = customerBizplace.company?.domain\n }\n return await bizplaceRepo.findOne({ where: { domain: { id: companyDomain.id } }, relations: ['domain'] })\n}\n\nexport async function getCompaniesBizplaces(\n domains: Domain[],\n warehouseDomain: Domain,\n tx?: EntityManager\n): Promise<Bizplace[]> {\n const bizplaceRepo = tx ? tx.getRepository(Bizplace) : getRepository(Bizplace)\n\n const partnersBizplaces = await bizplaceRepo\n .createQueryBuilder('b')\n .select('b.id', 'id')\n .addSelect('b.name', 'name')\n .addSelect('b.description', 'description')\n .innerJoin('companies', 'c', 'c.domain_id = b.domain_id')\n .innerJoin('bizplaces', 'b2', 'b2.company_id = c.id')\n .innerJoin('domains', 'd', 'd.id = b2.domain_id')\n .innerJoin('partners', 'p', 'p.partner_domain_id = d.id')\n .where('p.domain_id = :domainId', { domainId: warehouseDomain.id })\n .andWhere('b2.domain_id IN (:...domainIds)', { domainIds: domains.map(domain => domain.id) })\n .groupBy('b.id')\n .addGroupBy('b.name')\n .addGroupBy('b.description')\n .getRawMany()\n\n return partnersBizplaces\n}\n\nexport async function getPartnerBizplaceIds(domain: Domain, user: User, tx?: EntityManager): Promise<string[] | any[]> {\n const bizplaceRepo = tx ? tx.getRepository(Bizplace) : getRepository(Bizplace)\n const partnerRepo = tx ? tx.getRepository(Partner) : getRepository(Partner)\n\n let partnerBizplaces: Bizplace[] = []\n\n const domainBizplace: Bizplace = await bizplaceRepo.findOne({ where: { domain: { id: domain.id } } })\n if (!domainBizplace) {\n } else {\n const partners: Partner[] = await partnerRepo.find({\n where: { domain: { id: domainBizplace.id } } /* CONFIRMME regarding TYPEORM - compare original logic */,\n relations: ['partnerBizplace', 'partnerBizplace.company', 'partnerBizplace.company.domain']\n })\n\n for (let partner of partners) {\n partnerBizplaces.push((partner as any).partnerBizplace)\n }\n }\n return partnerBizplaces.map((bizplace: Bizplace) => bizplace.id || null)\n}\n\nexport async function getPartnersBizplaces(domain: Domain, user: User, tx?: EntityManager): Promise<Bizplace[]> {\n const userRepo = tx ? tx.getRepository(User) : getRepository(User)\n const bizplaceRepo = tx ? tx.getRepository(Bizplace) : getRepository(Bizplace)\n const partnerRepo = tx ? tx.getRepository(Partner) : getRepository(Partner)\n\n let partnersBizplaces: Bizplace[] = []\n\n const qb: SelectQueryBuilder<User> = userRepo\n .createQueryBuilder('user')\n .select('user.id', 'userId')\n .addSelect('role.id', 'roleId')\n .addSelect('role.name', 'roleName')\n .addSelect('domain.id', 'domainId')\n .addSelect('domain.name', 'domainName')\n .innerJoin('users_roles', 'ur', 'user.id = ur.users_id')\n .innerJoin('roles', 'role', 'ur.roles_id = role.id')\n .innerJoin('domains', 'domain', 'role.domain_id = domain.id')\n .where('user.id = :userId', { userId: user.id })\n .andWhere('domain.id = :domainId', { domainId: domain.id })\n\n let userRoles = await qb.getRawMany()\n\n // detect if user is Customer\n let foundCustomerRole = userRoles.find(role => role.roleName === 'Customer')\n\n // get all partners\n let partnersDomains: Partner[] = await partnerRepo.find({\n where: { domain: { id: domain.id } },\n relations: ['partnerDomain']\n })\n\n if (foundCustomerRole) {\n let userDomains = user.domains\n for (let partDomain of partnersDomains) {\n for (let userDomain of userDomains) {\n if (userDomain.id === partDomain.partnerDomain.id) {\n let partnerBizplace: Bizplace = await bizplaceRepo.findOne({\n where: { domain: { id: partDomain.partnerDomain.id } },\n relations: ['company', 'company.domain']\n })\n\n partnersBizplaces.push(partnerBizplace)\n }\n }\n }\n } else {\n for (let partDomain of partnersDomains) {\n let partnerBizplace: Bizplace = await bizplaceRepo.findOne({\n where: { domain: { id: partDomain.partnerDomain.id } },\n relations: ['company', 'company.domain']\n })\n\n partnersBizplaces.push(partnerBizplace)\n }\n }\n\n return partnersBizplaces\n}\n\nexport async function getPartnersCompanyBizplaces(\n domain: Domain,\n user: User,\n strictAccess: Boolean = false,\n tx?: EntityManager\n): Promise<Bizplace[]> {\n const userRepo = tx ? tx.getRepository(User) : getRepository(User)\n const bizplaceRepo = tx ? tx.getRepository(Bizplace) : getRepository(Bizplace)\n\n let partnersBizplaces: Bizplace[] = []\n\n let userRoles: any = await userRepo\n .createQueryBuilder('user')\n .select('user.id', 'userId')\n .addSelect('role.id', 'roleId')\n .addSelect('role.name', 'roleName')\n .addSelect('domain.id', 'domainId')\n .addSelect('domain.name', 'domainName')\n .innerJoin('users_roles', 'ur', 'user.id = ur.users_id')\n .innerJoin('roles', 'role', 'ur.roles_id = role.id')\n .innerJoin('domains', 'domain', 'role.domain_id = domain.id')\n .where('user.id = :userId', { userId: user.id })\n .andWhere('domain.id = :domainId', { domainId: domain.id })\n .getRawMany()\n\n if (userRoles.find(role => role.roleName !== 'Customer')) {\n let qbPartnersBizplaces = bizplaceRepo\n .createQueryBuilder('b')\n .select('b.id', 'id')\n .addSelect('b.name', 'name')\n .addSelect('b.description', 'description')\n .innerJoin('companies', 'c', 'c.domain_id = b.domain_id')\n .innerJoin('bizplaces', 'b2', 'b2.company_id = c.id')\n .innerJoin('domains', 'd', 'd.id = b2.domain_id')\n .innerJoin('partners', 'p', 'p.partner_domain_id = d.id')\n .where('p.domain_id = :domainId', { domainId: domain.id })\n .groupBy('b.id')\n .addGroupBy('b.name')\n .addGroupBy('b.description')\n\n if (strictAccess) {\n const userRepo = tx ? tx.getRepository(User) : getRepository(User)\n qbPartnersBizplaces.andWhere(\n `exists (\n ${userRepo\n .createQueryBuilder('u2')\n .innerJoin('users_roles', 'ur', 'ur.users_id = u2.id')\n .innerJoin('roles', 'r', 'r.id = ur.roles_id')\n .where('r.domain_id = c.domain_id')\n .andWhere(`r.name IN ('BUSINESS-OWNER','BUSINESS-MANAGER')`)\n .andWhere(`u2.id = '${user.id}'`)\n .getQuery()})`\n )\n }\n\n partnersBizplaces = await qbPartnersBizplaces.getRawMany()\n }\n\n return partnersBizplaces\n}\n\nexport async function getCustomerBizplaces(domain: Domain, tx?: EntityManager): Promise<Bizplace[]> {\n const partnerRepo = tx ? tx.getRepository(Partner) : getRepository(Partner)\n const bizplaceRepo = tx ? tx.getRepository(Bizplace) : getRepository(Bizplace)\n\n const customers: Partner[] = await partnerRepo.find({\n where: { domain: { id: domain.id } },\n relations: ['partnerDomain']\n })\n const customerDomains: Domain[] = customers.map((customer: Partner) => customer.partnerDomain)\n return await bizplaceRepo.find({\n where: { domain: In(customerDomains.map((d: Domain) => d.id)) },\n relations: ['company', 'company.domain', 'domain']\n })\n}\n\nexport async function getSubdomainBizplace(subdomain: string, tx?: EntityManager): Promise<Bizplace> {\n const domainRepo = tx ? tx.getRepository(Domain) : getRepository(Domain)\n\n const domain: Domain = await domainRepo.findOne({\n where: { subdomain }\n })\n\n return await getRepository(Bizplace).findOne({ where: { domain: { id: domain.id } } })\n}\n\nexport async function getUserBizplaces(user: User, tx?: EntityManager): Promise<Bizplace[]> {\n const userRepo = tx ? tx.getRepository(User) : getRepository(User)\n let userBizplaces: Bizplace[] = []\n\n if (!user.domains?.length) {\n user = await userRepo.findOne({\n where: { id: user.id },\n relations: ['domains']\n })\n }\n\n const userDomains: Domain[] = user.domains\n if (userDomains.every((userDomain: Domain) => userDomain.extType !== 'company')) {\n userBizplaces.push(await getCompanyBizplace(userDomains[0], user, null, tx))\n }\n\n return userBizplaces.concat(\n await getRepository(Bizplace).find({ where: { domain: In(userDomains.map((d: Domain) => d.id)) } })\n )\n}\n\nexport async function getDomainUsers(bizplace: Bizplace, tx?: EntityManager): Promise<any[]> {\n const userDomainRepo = tx ? tx.getRepository('users_domains') : getRepository('users_domains')\n\n const users: any[] = await userDomainRepo\n .createQueryBuilder('ud')\n .select('ud.users_id', 'id')\n .distinct(true)\n .where(qb => {\n const subquery = qb\n .subQuery()\n .select('bizplace.domain_id')\n .from(Bizplace, 'bizplace')\n .where('bizplace.id = :customerBizplaceId', { customerBizplaceId: bizplace?.id })\n .getQuery()\n return 'ud.domains_id = ' + subquery\n })\n .getRawMany()\n\n return users\n}\n"]}
|
|
1
|
+
{"version":3,"file":"get-permitted-bizplaces.js","sourceRoot":"","sources":["../../server/utils/get-permitted-bizplaces.ts"],"names":[],"mappings":";;AAcA,sDAmBC;AAED,0DAGC;AAED,sCA0BC;AAED,8CAOC;AAED,gDA8BC;AAED,sDAwBC;AAED,sDAmBC;AAED,oDAyDC;AAED,kEA2DC;AAED,oDAaC;AAED,oDAQC;AAED,4CAmBC;AAED,wCAmBC;AArVD,qCAA+D;AAE/D,yDAAiF;AACjF,iDAA6D;AAE7D,2DAAuD;AAEvD;;;;;;GAMG;AACI,KAAK,UAAU,qBAAqB,CAAC,MAAc,EAAE,IAAU,EAAE,EAAkB;IACxF,MAAM,YAAY,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,mBAAQ,CAAC,CAAC,CAAC,CAAC,IAAA,qBAAa,EAAC,mBAAQ,CAAC,CAAA;IAE9E,qDAAqD;IACrD,IAAI,kBAAkB,GAAe,EAAE,CAAA;IACvC,IAAI,MAAM,IAAA,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EAAC,eAAe,CAAC,CAAA;IAE9F,MAAM,KAAK,GAAU,MAAM,cAAc;SACtC,kBAAkB,CAAC,IAAI,CAAC;SACxB,MAAM,CAAC,aAAa,EAAE,IAAI,CAAC;SAC3B,QAAQ,CAAC,IAAI,CAAC;SACd,KAAK,CAAC,EAAE,CAAC,EAAE;QACV,MAAM,QAAQ,GAAG,EAAE;aAChB,QAAQ,EAAE;aACV,MAAM,CAAC,oBAAoB,CAAC;aAC5B,IAAI,CAAC,mBAAQ,EAAE,UAAU,CAAC;aAC1B,KAAK,CAAC,mCAAmC,EAAE,EAAE,kBAAkB,EAAE,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,EAAE,EAAE,CAAC;aAChF,QAAQ,EAAE,CAAA;QACb,OAAO,kBAAkB,GAAG,QAAQ,CAAA;IACtC,CAAC,CAAC;SACD,UAAU,EAAE,CAAA;IAEf,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import { EntityManager, In, SelectQueryBuilder } from 'typeorm'\n\nimport { checkUserBelongsDomain, Partner, User } from '@things-factory/auth-base'\nimport { Domain, getRepository } from '@things-factory/shell'\n\nimport { Bizplace } from '../service/bizplace/bizplace'\n\n/**\n * @description 도메인과 사용자의 관계를 판단하여\n * 접속한 도메인을 통해 접근 할 수 있는 대상 bizplaces를 찾아 return\n *\n * @param domain\n * @param user\n */\nexport async function getPermittedBizplaces(domain: Domain, user: User, tx?: EntityManager): Promise<Bizplace[]> {\n const bizplaceRepo = tx ? tx.getRepository(Bizplace) : getRepository(Bizplace)\n\n // 1. Check whether `user` belongs to `domain` or not\n let permittedBizplaces: Bizplace[] = []\n if (await checkUserBelongsDomain(domain, user)) {\n // If `user` belongs to `domain`\n // return set of company bizplace, bizplace of passed domain, bizplaces of customers\n\n if (domain.extType !== 'company') permittedBizplaces.push(await getCompanyBizplace(domain, user, null, tx))\n permittedBizplaces.push(await bizplaceRepo.findOne({ where: { domain: { id: domain.id } } }))\n permittedBizplaces = permittedBizplaces.concat(await getCustomerBizplaces(domain, tx))\n } else {\n // If `user` doesn't belong to `domain`\n // return set of company bizplace, bizplaces which `user` can access\n permittedBizplaces = await getUserBizplaces(user)\n }\n\n return permittedBizplaces\n}\n\nexport async function getPermittedBizplaceIds(domain: Domain, user: User): Promise<string[] | any[]> {\n const bizplaces: Bizplace[] = await getPermittedBizplaces(domain, user)\n return bizplaces.map((bizplace: Bizplace) => bizplace.id || null)\n}\n\nexport async function getMyBizplace(domain: Domain, user: User, tx?: EntityManager): Promise<Bizplace> {\n const bizplaceRepo = tx ? tx.getRepository(Bizplace) : getRepository(Bizplace)\n\n // Case 1. 도메인에 소속된 사용자\n // 1. 현재 도메인을 릴레이션으로 가지고 있는 비즈플레이스를 리턴\n\n if (await checkUserBelongsDomain(domain, user)) {\n return await bizplaceRepo.findOne({ where: { domain: { id: domain.id } } })\n } else {\n const customerBizplaces: Bizplace[] = await getCustomerBizplaces(domain, tx)\n const userBizplaces: Bizplace[] = await getUserBizplaces(user, tx)\n\n const customerBizplaceIdSet: Set<string> = new Set(customerBizplaces.map((pb: Bizplace) => pb.id))\n const userBizplaceIdSet: Set<string> = new Set(userBizplaces.map((ub: Bizplace) => ub.id))\n\n const myBizplaceIds: string[] = Array.from(customerBizplaceIdSet).filter((pbId: string) =>\n userBizplaceIdSet.has(pbId)\n )\n if (myBizplaceIds.length > 1) console.warn(`User has multiple bizplaces ${myBizplaceIds}`)\n\n // TODO: 복수의 비즈플레이스를 가지고 있는 사용자는 조회 결과의 첫번째 비즈플레이스만 리턴 받도록 되어 있음\n // 이런 케이스에 처리 방식을 결정하고 수정해야함\n return await bizplaceRepo.findOne({\n where: { id: In(myBizplaceIds) }\n })\n }\n}\n\nexport async function getOutletBizplace(outletId: string, tx?: EntityManager) {\n const bizplaceRepo = tx ? tx.getRepository(Bizplace) : getRepository(Bizplace)\n\n const bizplace: Bizplace = await bizplaceRepo.findOne({\n where: { id: outletId }\n })\n return bizplace\n}\n\nexport async function getCompanyBizplace(\n domain: Domain,\n user: User,\n customerBizplaceId?: string,\n tx?: EntityManager\n): Promise<Bizplace> {\n const bizplaceRepo = tx ? tx.getRepository(Bizplace) : getRepository(Bizplace)\n\n let companyDomain: Domain\n\n if (user) {\n let myBizplace: Bizplace = await getMyBizplace(domain, user, tx)\n if (!myBizplace.company?.id) {\n myBizplace = await bizplaceRepo.findOne({\n where: { id: myBizplace.id },\n relations: ['company', 'company.domain']\n })\n companyDomain = myBizplace.company.domain\n }\n }\n\n if (customerBizplaceId) {\n const customerBizplace: Bizplace = await bizplaceRepo.findOne({\n where: { id: customerBizplaceId },\n relations: ['company', 'company.domain']\n })\n\n companyDomain = customerBizplace.company?.domain\n }\n return await bizplaceRepo.findOne({ where: { domain: { id: companyDomain.id } }, relations: ['domain'] })\n}\n\nexport async function getCompaniesBizplaces(\n domains: Domain[],\n warehouseDomain: Domain,\n tx?: EntityManager\n): Promise<Bizplace[]> {\n const bizplaceRepo = tx ? tx.getRepository(Bizplace) : getRepository(Bizplace)\n\n const partnersBizplaces = await bizplaceRepo\n .createQueryBuilder('b')\n .select('b.id', 'id')\n .addSelect('b.name', 'name')\n .addSelect('b.description', 'description')\n .innerJoin('companies', 'c', 'c.domain_id = b.domain_id')\n .innerJoin('bizplaces', 'b2', 'b2.company_id = c.id')\n .innerJoin('domains', 'd', 'd.id = b2.domain_id')\n .innerJoin('partners', 'p', 'p.partner_domain_id = d.id')\n .where('p.domain_id = :domainId', { domainId: warehouseDomain.id })\n .andWhere('b2.domain_id IN (:...domainIds)', { domainIds: domains.map(domain => domain.id) })\n .groupBy('b.id')\n .addGroupBy('b.name')\n .addGroupBy('b.description')\n .getRawMany()\n\n return partnersBizplaces\n}\n\nexport async function getPartnerBizplaceIds(domain: Domain, user: User, tx?: EntityManager): Promise<string[] | any[]> {\n const bizplaceRepo = tx ? tx.getRepository(Bizplace) : getRepository(Bizplace)\n const partnerRepo = tx ? tx.getRepository(Partner) : getRepository(Partner)\n\n let partnerBizplaces: Bizplace[] = []\n\n const domainBizplace: Bizplace = await bizplaceRepo.findOne({ where: { domain: { id: domain.id } } })\n if (!domainBizplace) {\n } else {\n const partners: Partner[] = await partnerRepo.find({\n where: { domain: { id: domainBizplace.id } } /* CONFIRMME regarding TYPEORM - compare original logic */,\n relations: ['partnerBizplace', 'partnerBizplace.company', 'partnerBizplace.company.domain']\n })\n\n for (let partner of partners) {\n partnerBizplaces.push((partner as any).partnerBizplace)\n }\n }\n return partnerBizplaces.map((bizplace: Bizplace) => bizplace.id || null)\n}\n\nexport async function getPartnersBizplaces(domain: Domain, user: User, tx?: EntityManager): Promise<Bizplace[]> {\n const userRepo = tx ? tx.getRepository(User) : getRepository(User)\n const bizplaceRepo = tx ? tx.getRepository(Bizplace) : getRepository(Bizplace)\n const partnerRepo = tx ? tx.getRepository(Partner) : getRepository(Partner)\n\n let partnersBizplaces: Bizplace[] = []\n\n const qb: SelectQueryBuilder<User> = userRepo\n .createQueryBuilder('user')\n .select('user.id', 'userId')\n .addSelect('role.id', 'roleId')\n .addSelect('role.name', 'roleName')\n .addSelect('domain.id', 'domainId')\n .addSelect('domain.name', 'domainName')\n .innerJoin('users_roles', 'ur', 'user.id = ur.users_id')\n .innerJoin('roles', 'role', 'ur.roles_id = role.id')\n .innerJoin('domains', 'domain', 'role.domain_id = domain.id')\n .where('user.id = :userId', { userId: user.id })\n .andWhere('domain.id = :domainId', { domainId: domain.id })\n\n let userRoles = await qb.getRawMany()\n\n // detect if user is Customer\n let foundCustomerRole = userRoles.find(role => role.roleName === 'Customer')\n\n // get all partners\n let partnersDomains: Partner[] = await partnerRepo.find({\n where: { domain: { id: domain.id } },\n relations: ['partnerDomain']\n })\n\n if (foundCustomerRole) {\n let userDomains = user.domains\n for (let partDomain of partnersDomains) {\n for (let userDomain of userDomains) {\n if (userDomain.id === partDomain.partnerDomain.id) {\n let partnerBizplace: Bizplace = await bizplaceRepo.findOne({\n where: { domain: { id: partDomain.partnerDomain.id } },\n relations: ['company', 'company.domain']\n })\n\n partnersBizplaces.push(partnerBizplace)\n }\n }\n }\n } else {\n for (let partDomain of partnersDomains) {\n let partnerBizplace: Bizplace = await bizplaceRepo.findOne({\n where: { domain: { id: partDomain.partnerDomain.id } },\n relations: ['company', 'company.domain']\n })\n\n partnersBizplaces.push(partnerBizplace)\n }\n }\n\n return partnersBizplaces\n}\n\nexport async function getPartnersCompanyBizplaces(\n domain: Domain,\n user: User,\n strictAccess: Boolean = false,\n tx?: EntityManager\n): Promise<Bizplace[]> {\n const userRepo = tx ? tx.getRepository(User) : getRepository(User)\n const bizplaceRepo = tx ? tx.getRepository(Bizplace) : getRepository(Bizplace)\n\n let partnersBizplaces: Bizplace[] = []\n\n let userRoles: any = await userRepo\n .createQueryBuilder('user')\n .select('user.id', 'userId')\n .addSelect('role.id', 'roleId')\n .addSelect('role.name', 'roleName')\n .addSelect('domain.id', 'domainId')\n .addSelect('domain.name', 'domainName')\n .innerJoin('users_roles', 'ur', 'user.id = ur.users_id')\n .innerJoin('roles', 'role', 'ur.roles_id = role.id')\n .innerJoin('domains', 'domain', 'role.domain_id = domain.id')\n .where('user.id = :userId', { userId: user.id })\n .andWhere('domain.id = :domainId', { domainId: domain.id })\n .getRawMany()\n\n if (userRoles.find(role => role.roleName !== 'Customer')) {\n let qbPartnersBizplaces = bizplaceRepo\n .createQueryBuilder('b')\n .select('b.id', 'id')\n .addSelect('b.name', 'name')\n .addSelect('b.description', 'description')\n .innerJoin('companies', 'c', 'c.domain_id = b.domain_id')\n .innerJoin('bizplaces', 'b2', 'b2.company_id = c.id')\n .innerJoin('domains', 'd', 'd.id = b2.domain_id')\n .innerJoin('partners', 'p', 'p.partner_domain_id = d.id')\n .where('p.domain_id = :domainId', { domainId: domain.id })\n .groupBy('b.id')\n .addGroupBy('b.name')\n .addGroupBy('b.description')\n\n if (strictAccess) {\n const userRepo = tx ? tx.getRepository(User) : getRepository(User)\n qbPartnersBizplaces.andWhere(\n `exists (\n ${userRepo\n .createQueryBuilder('u2')\n .innerJoin('users_roles', 'ur', 'ur.users_id = u2.id')\n .innerJoin('roles', 'r', 'r.id = ur.roles_id')\n .where('r.domain_id = c.domain_id')\n .andWhere(`r.name IN ('BUSINESS-OWNER','BUSINESS-MANAGER')`)\n .andWhere(`u2.id = '${user.id}'`)\n .getQuery()})`\n )\n }\n\n partnersBizplaces = await qbPartnersBizplaces.getRawMany()\n }\n\n return partnersBizplaces\n}\n\nexport async function getCustomerBizplaces(domain: Domain, tx?: EntityManager): Promise<Bizplace[]> {\n const partnerRepo = tx ? tx.getRepository(Partner) : getRepository(Partner)\n const bizplaceRepo = tx ? tx.getRepository(Bizplace) : getRepository(Bizplace)\n\n const customers: Partner[] = await partnerRepo.find({\n where: { domain: { id: domain.id } },\n relations: ['partnerDomain']\n })\n const customerDomains: Domain[] = customers.map((customer: Partner) => customer.partnerDomain)\n return await bizplaceRepo.find({\n where: { domain: In(customerDomains.map((d: Domain) => d.id)) },\n relations: ['company', 'company.domain', 'domain']\n })\n}\n\nexport async function getSubdomainBizplace(subdomain: string, tx?: EntityManager): Promise<Bizplace> {\n const domainRepo = tx ? tx.getRepository(Domain) : getRepository(Domain)\n\n const domain: Domain = await domainRepo.findOne({\n where: { subdomain }\n })\n\n return await getRepository(Bizplace).findOne({ where: { domain: { id: domain.id } } })\n}\n\nexport async function getUserBizplaces(user: User, tx?: EntityManager): Promise<Bizplace[]> {\n const userRepo = tx ? tx.getRepository(User) : getRepository(User)\n let userBizplaces: Bizplace[] = []\n\n if (!user.domains?.length) {\n user = await userRepo.findOne({\n where: { id: user.id },\n relations: ['domains']\n })\n }\n\n const userDomains: Domain[] = user.domains\n if (userDomains.every((userDomain: Domain) => userDomain.extType !== 'company')) {\n userBizplaces.push(await getCompanyBizplace(userDomains[0], user, null, tx))\n }\n\n return userBizplaces.concat(\n await getRepository(Bizplace).find({ where: { domain: In(userDomains.map((d: Domain) => d.id)) } })\n )\n}\n\nexport async function getDomainUsers(bizplace: Bizplace, tx?: EntityManager): Promise<any[]> {\n const userDomainRepo = tx ? tx.getRepository('users_domains') : getRepository('users_domains')\n\n const users: any[] = await userDomainRepo\n .createQueryBuilder('ud')\n .select('ud.users_id', 'id')\n .distinct(true)\n .where(qb => {\n const subquery = qb\n .subQuery()\n .select('bizplace.domain_id')\n .from(Bizplace, 'bizplace')\n .where('bizplace.id = :customerBizplaceId', { customerBizplaceId: bizplace?.id })\n .getQuery()\n return 'ud.domains_id = ' + subquery\n })\n .getRawMany()\n\n return users\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './get-permitted-bizplaces';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/biz-base",
|
|
3
|
-
"version": "7.0.0
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@things-factory/auth-base": "^7.0.0
|
|
27
|
+
"@things-factory/auth-base": "^7.0.0"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "00f3917ca132679e3571f3f4fd16f4caf84f488e"
|
|
30
30
|
}
|
|
@@ -16,7 +16,10 @@ export class BizOptionQuery {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
@Query(returns => BizOptionList)
|
|
19
|
-
async bizOptions(
|
|
19
|
+
async bizOptions(
|
|
20
|
+
@Args(type => ListParam) params: ListParam,
|
|
21
|
+
@Ctx() context: ResolverContext
|
|
22
|
+
): Promise<BizOptionList> {
|
|
20
23
|
const convertedParams = convertListParams(params)
|
|
21
24
|
const [items, total] = await getRepository(BizOption).findAndCount({
|
|
22
25
|
...convertedParams,
|
|
@@ -16,7 +16,7 @@ export class BizOptionDetailQuery {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
@Query(returns => BizOptionDetailList)
|
|
19
|
-
async bizOptionDetails(@Args() params: ListParam): Promise<BizOptionDetailList> {
|
|
19
|
+
async bizOptionDetails(@Args(type => ListParam) params: ListParam): Promise<BizOptionDetailList> {
|
|
20
20
|
const convertedParams = convertListParams(params)
|
|
21
21
|
const [items, total] = await getRepository(BizOptionDetail).findAndCount({
|
|
22
22
|
...convertedParams,
|
|
@@ -71,7 +71,7 @@ export class BizplaceQuery {
|
|
|
71
71
|
|
|
72
72
|
@Directive('@privilege(category: "bizplace", privilege: "query", domainOwnerGranted: true)')
|
|
73
73
|
@Query(returns => BizplaceList)
|
|
74
|
-
async bizplaces(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<BizplaceList> {
|
|
74
|
+
async bizplaces(@Args(type => ListParam) params: ListParam, @Ctx() context: ResolverContext): Promise<BizplaceList> {
|
|
75
75
|
let bizplace_ids = []
|
|
76
76
|
let bizplaceIndex: any = params.filters.findIndex(x => x.name === 'bizplace')
|
|
77
77
|
if (bizplaceIndex > -1) {
|
|
@@ -112,7 +112,7 @@ export class BizplaceQuery {
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
@Query(returns => UserList)
|
|
115
|
-
async bizplaceUsers(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<UserList> {
|
|
115
|
+
async bizplaceUsers(@Args(type => ListParam) params: ListParam, @Ctx() context: ResolverContext): Promise<UserList> {
|
|
116
116
|
const { domain, user } = context.state
|
|
117
117
|
const myBizplace: Bizplace = await getMyBizplace(domain, user)
|
|
118
118
|
return await bizplaceUsers(myBizplace, {
|
|
@@ -122,7 +122,10 @@ export class BizplaceQuery {
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
@Query(returns => BizplaceList)
|
|
125
|
-
async partnersBizplaces(
|
|
125
|
+
async partnersBizplaces(
|
|
126
|
+
@Args(type => ListParam) params: ListParam,
|
|
127
|
+
@Ctx() context: ResolverContext
|
|
128
|
+
): Promise<BizplaceList> {
|
|
126
129
|
let partnersBizplaceIds = []
|
|
127
130
|
let bizplaceIndex: any = params.filters.findIndex(x => x.name === 'bizplace')
|
|
128
131
|
if (bizplaceIndex > -1) {
|
|
@@ -164,7 +167,7 @@ export class BizplaceQuery {
|
|
|
164
167
|
|
|
165
168
|
@Query(returns => BizplaceList)
|
|
166
169
|
async permittedPartnersCompanyBizplaces(
|
|
167
|
-
@Args() params: ListParam,
|
|
170
|
+
@Args(type => ListParam) params: ListParam,
|
|
168
171
|
@Ctx() context: ResolverContext
|
|
169
172
|
): Promise<BizplaceList> {
|
|
170
173
|
let partnersBizplaceIds = []
|
|
@@ -28,8 +28,8 @@ export class Bizplace {
|
|
|
28
28
|
readonly id: string
|
|
29
29
|
|
|
30
30
|
@ManyToOne(type => Domain)
|
|
31
|
-
@Field()
|
|
32
|
-
domain
|
|
31
|
+
@Field(type => Domain)
|
|
32
|
+
domain?: Domain
|
|
33
33
|
|
|
34
34
|
@OneToMany(type => BizOption, bizOption => bizOption.bizplace)
|
|
35
35
|
@Field(type => [BizOption], { nullable: true })
|
|
@@ -26,7 +26,7 @@ export class CompanyQuery {
|
|
|
26
26
|
|
|
27
27
|
@Directive('@privilege(category: "company", privilege: "query")')
|
|
28
28
|
@Query(returns => CompanyList)
|
|
29
|
-
async companies(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<CompanyList> {
|
|
29
|
+
async companies(@Args(type => ListParam) params: ListParam, @Ctx() context: ResolverContext): Promise<CompanyList> {
|
|
30
30
|
const { domain } = context.state
|
|
31
31
|
const convertedParams = convertListParams(params, { domain })
|
|
32
32
|
|
|
@@ -18,7 +18,10 @@ export class ContactPointQuery {
|
|
|
18
18
|
|
|
19
19
|
@Directive('@privilege(category: "contact_point", privilege: "query", domainOwnerGranted: true)')
|
|
20
20
|
@Query(returns => ContactPointList)
|
|
21
|
-
async contactPoints(
|
|
21
|
+
async contactPoints(
|
|
22
|
+
@Args(type => ListParam) params: ListParam,
|
|
23
|
+
@Ctx() context: ResolverContext
|
|
24
|
+
): Promise<ContactPointList> {
|
|
22
25
|
const { domain } = context.state
|
|
23
26
|
const queryBuilder = await getQueryBuilderFromListParams({
|
|
24
27
|
repository: getRepository(ContactPoint),
|
|
@@ -30,6 +30,9 @@ export class ContactPointPatch {
|
|
|
30
30
|
@Field({ nullable: true })
|
|
31
31
|
companyName?: string
|
|
32
32
|
|
|
33
|
+
@Field({ nullable: true })
|
|
34
|
+
representativeName?: string
|
|
35
|
+
|
|
33
36
|
@Field({ nullable: true })
|
|
34
37
|
managerName?: string
|
|
35
38
|
|
|
@@ -129,6 +132,9 @@ export class NewContactPoint {
|
|
|
129
132
|
@Field({ nullable: true })
|
|
130
133
|
phone2?: string
|
|
131
134
|
|
|
135
|
+
@Field({ nullable: true })
|
|
136
|
+
representativeName?: string
|
|
137
|
+
|
|
132
138
|
@Field({ nullable: true })
|
|
133
139
|
managerName?: string
|
|
134
140
|
|
|
@@ -19,14 +19,7 @@ import { Bizplace } from '../bizplace/bizplace'
|
|
|
19
19
|
],
|
|
20
20
|
{ unique: true }
|
|
21
21
|
)
|
|
22
|
-
@Index(
|
|
23
|
-
'ix_contact_points_1',
|
|
24
|
-
(contactPoint: ContactPoint) => [
|
|
25
|
-
contactPoint.registrationNo,
|
|
26
|
-
contactPoint.type
|
|
27
|
-
],
|
|
28
|
-
{ unique: true }
|
|
29
|
-
)
|
|
22
|
+
@Index('ix_contact_points_1', (contactPoint: ContactPoint) => [contactPoint.registrationNo, contactPoint.type])
|
|
30
23
|
@ObjectType()
|
|
31
24
|
export class ContactPoint {
|
|
32
25
|
@PrimaryGeneratedColumn('uuid')
|
|
@@ -34,8 +27,8 @@ export class ContactPoint {
|
|
|
34
27
|
id: string
|
|
35
28
|
|
|
36
29
|
@ManyToOne(type => Domain)
|
|
37
|
-
@Field()
|
|
38
|
-
domain
|
|
30
|
+
@Field(type => Domain)
|
|
31
|
+
domain?: Domain
|
|
39
32
|
|
|
40
33
|
@ManyToOne(type => Bizplace)
|
|
41
34
|
@Field(type => Bizplace)
|
|
@@ -93,6 +86,10 @@ export class ContactPoint {
|
|
|
93
86
|
@Field({ nullable: true })
|
|
94
87
|
companyName: string
|
|
95
88
|
|
|
89
|
+
@Column({ nullable: true })
|
|
90
|
+
@Field({ nullable: true })
|
|
91
|
+
representativeName: string
|
|
92
|
+
|
|
96
93
|
@Column({ nullable: true })
|
|
97
94
|
@Field({ nullable: true })
|
|
98
95
|
managerName: string
|
|
@@ -24,7 +24,7 @@ export class WorkerQuery {
|
|
|
24
24
|
|
|
25
25
|
@Directive('@privilege(category: "worker", privilege: "query", domainOwnerGranted: true)')
|
|
26
26
|
@Query(returns => WorkerList)
|
|
27
|
-
async workers(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<WorkerList> {
|
|
27
|
+
async workers(@Args(type => ListParam) params: ListParam, @Ctx() context: ResolverContext): Promise<WorkerList> {
|
|
28
28
|
const convertedParams = convertListParams(params)
|
|
29
29
|
convertedParams.where.bizplace = In(await getPermittedBizplaceIds(context.state.domain, context.state.user))
|
|
30
30
|
const [items, total] = await getRepository(Worker).findAndCount({
|