@things-factory/biz-base 10.1.228 → 10.1.231
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 +1 -0
- package/dist-server/index.js +1 -0
- package/dist-server/index.js.map +1 -1
- package/dist-server/service/company/company-mutation.d.ts +14 -0
- package/dist-server/service/company/company-mutation.js +62 -2
- package/dist-server/service/company/company-mutation.js.map +1 -1
- package/dist-server/service/company/company-query.d.ts +3 -1
- package/dist-server/service/company/company-query.js +15 -8
- package/dist-server/service/company/company-query.js.map +1 -1
- package/dist-server/service/company/company-seal-reader.d.ts +6 -0
- package/dist-server/service/company/company-seal-reader.js +16 -0
- package/dist-server/service/company/company-seal-reader.js.map +1 -0
- package/dist-server/service/company/company-types.d.ts +3 -0
- package/dist-server/service/company/company-types.js +12 -0
- package/dist-server/service/company/company-types.js.map +1 -1
- package/dist-server/service/company/company.d.ts +3 -0
- package/dist-server/service/company/company.js +26 -6
- package/dist-server/service/company/company.js.map +1 -1
- package/dist-server/service/company/our-company.d.ts +44 -0
- package/dist-server/service/company/our-company.js +55 -0
- package/dist-server/service/company/our-company.js.map +1 -0
- package/dist-server/service/index.d.ts +2 -1
- package/dist-server/service/index.js +4 -1
- package/dist-server/service/index.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/tests/our-company.test.mjs +75 -0
- package/translations/en.json +3 -1
- package/translations/es.json +3 -1
- package/translations/ja.json +3 -1
- package/translations/ko.json +3 -1
- package/translations/ms.json +3 -1
- package/translations/zh.json +3 -1
package/dist-server/index.d.ts
CHANGED
package/dist-server/index.js
CHANGED
|
@@ -5,6 +5,7 @@ tslib_1.__exportStar(require("./service"), exports);
|
|
|
5
5
|
tslib_1.__exportStar(require("./migrations"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./utils"), exports);
|
|
7
7
|
require("./service/counterparty/counterparty-document-readers");
|
|
8
|
+
require("./service/company/company-seal-reader");
|
|
8
9
|
const auth_base_1 = require("@things-factory/auth-base");
|
|
9
10
|
const role_tasks_1 = require("./role-tasks");
|
|
10
11
|
for (const task of role_tasks_1.ROLE_TASKS)
|
package/dist-server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;AAAA,oDAAyB;AACzB,uDAA4B;AAC5B,kDAAuB;AAEvB,gEAA6D;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;AAAA,oDAAyB;AACzB,uDAA4B;AAC5B,kDAAuB;AAEvB,gEAA6D;AAC7D,iDAA8C;AAE9C,yDAA4D;AAC5D,6CAAyC;AAEzC,KAAK,MAAM,IAAI,IAAI,uBAAU;IAAE,IAAA,4BAAgB,EAAC,IAAI,CAAC,CAAA","sourcesContent":["export * from './service'\nexport * from './migrations'\nexport * from './utils'\n\nimport './service/counterparty/counterparty-document-readers'\nimport './service/company/company-seal-reader'\n\nimport { registerRoleTask } from '@things-factory/auth-base'\nimport { ROLE_TASKS } from './role-tasks'\n\nfor (const task of ROLE_TASKS) registerRoleTask(task)\n"]}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import type { FileUpload } from 'graphql-upload/GraphQLUpload.js';
|
|
1
2
|
import { EntityManager } from 'typeorm';
|
|
3
|
+
import { Attachment } from '@things-factory/attachment-base';
|
|
2
4
|
import { User } from '@things-factory/auth-base';
|
|
3
5
|
import { Domain } from '@things-factory/shell';
|
|
4
6
|
import { Company } from './company';
|
|
5
7
|
import { CompanyPatch, NewCompany } from './company-types';
|
|
6
8
|
export declare class CompanyMutation {
|
|
9
|
+
saveCompany(company: CompanyPatch, context: ResolverContext): Promise<Company>;
|
|
10
|
+
attachCompanySeal(companyId: string, file: FileUpload | null, context: ResolverContext): Promise<Attachment | null>;
|
|
7
11
|
createCompany(company: NewCompany, context: ResolverContext): Promise<Company>;
|
|
8
12
|
updateCompany(name: string, patch: CompanyPatch, context: ResolverContext): Promise<Company>;
|
|
9
13
|
updateMultipleCompany(patches: CompanyPatch[], context: ResolverContext): Promise<any[]>;
|
|
@@ -32,6 +36,9 @@ export declare function updateCompany(name: string, patch: CompanyPatch, domain:
|
|
|
32
36
|
brn: string;
|
|
33
37
|
address: string;
|
|
34
38
|
postalCode: string;
|
|
39
|
+
corporateRegistrationNumber: string;
|
|
40
|
+
representative: string;
|
|
41
|
+
phone: string;
|
|
35
42
|
status: string;
|
|
36
43
|
cuFlag?: string;
|
|
37
44
|
domain?: Domain;
|
|
@@ -46,3 +53,10 @@ export declare function updateCompany(name: string, patch: CompanyPatch, domain:
|
|
|
46
53
|
} & Company>;
|
|
47
54
|
export declare function deleteCompanies(ids: string[], tx?: EntityManager): Promise<import("typeorm").DeleteResult>;
|
|
48
55
|
export declare function deleteCompany(id: string, tx?: EntityManager): Promise<import("typeorm").DeleteResult>;
|
|
56
|
+
/** The words 「우리 회사」 keeps - what a save may set. */
|
|
57
|
+
export declare const OUR_COMPANY_FIELDS: readonly ["name", "representative", "brn", "corporateRegistrationNumber", "address", "phone"];
|
|
58
|
+
/**
|
|
59
|
+
* Keep this domain's own company: its row, made on the first save. Only the fields of 「우리 회사」 are taken, trimmed;
|
|
60
|
+
* a name is required - a document cannot print a company without one.
|
|
61
|
+
*/
|
|
62
|
+
export declare function saveOurCompany(patch: Partial<Company>, domain: Domain, user: User, tx: EntityManager): Promise<Company>;
|
|
@@ -1,17 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CompanyMutation = void 0;
|
|
3
|
+
exports.OUR_COMPANY_FIELDS = exports.CompanyMutation = void 0;
|
|
4
4
|
exports.createCompany = createCompany;
|
|
5
5
|
exports.updateCompany = updateCompany;
|
|
6
6
|
exports.deleteCompanies = deleteCompanies;
|
|
7
7
|
exports.deleteCompany = deleteCompany;
|
|
8
|
+
exports.saveOurCompany = saveOurCompany;
|
|
8
9
|
const tslib_1 = require("tslib");
|
|
10
|
+
const GraphQLUpload_js_1 = tslib_1.__importDefault(require("graphql-upload/GraphQLUpload.js"));
|
|
9
11
|
const type_graphql_1 = require("type-graphql");
|
|
12
|
+
const attachment_base_1 = require("@things-factory/attachment-base");
|
|
10
13
|
const shell_1 = require("@things-factory/shell");
|
|
11
14
|
const utils_1 = require("@things-factory/utils");
|
|
12
15
|
const company_1 = require("./company");
|
|
13
16
|
const company_types_1 = require("./company-types");
|
|
17
|
+
const our_company_1 = require("./our-company");
|
|
14
18
|
let CompanyMutation = class CompanyMutation {
|
|
19
|
+
async saveCompany(company, context) {
|
|
20
|
+
const { domain, user, tx } = context.state;
|
|
21
|
+
return await saveOurCompany(company, domain, user, tx);
|
|
22
|
+
}
|
|
23
|
+
async attachCompanySeal(companyId, file, context) {
|
|
24
|
+
const { domain, tx } = context.state;
|
|
25
|
+
const company = await (0, our_company_1.ourCompanyOf)(domain, tx);
|
|
26
|
+
if (!company || company.id !== companyId)
|
|
27
|
+
throw new shell_1.Refusal('company-not-found', {}, 'save the company first');
|
|
28
|
+
return await (0, attachment_base_1.replaceAttachment)({ file, refType: our_company_1.COMPANY_SEAL_REF_TYPE, refBy: company.id, category: 'seal' }, context);
|
|
29
|
+
}
|
|
15
30
|
async createCompany(company, context) {
|
|
16
31
|
const { domain, user, tx } = context.state;
|
|
17
32
|
return await createCompany(company, domain, user, tx);
|
|
@@ -50,6 +65,29 @@ let CompanyMutation = class CompanyMutation {
|
|
|
50
65
|
}
|
|
51
66
|
};
|
|
52
67
|
exports.CompanyMutation = CompanyMutation;
|
|
68
|
+
tslib_1.__decorate([
|
|
69
|
+
(0, type_graphql_1.Directive)('@privilege(category: "company", privilege: "mutation", domainOwnerGranted: true)'),
|
|
70
|
+
(0, type_graphql_1.Directive)('@auditTarget(kind: "Company", arg: "company")'),
|
|
71
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
|
72
|
+
(0, type_graphql_1.Mutation)(returns => company_1.Company, { description: "To keep 「우리 회사」 - this domain's own company, made on its first save (ADR-0176)" }),
|
|
73
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('company')),
|
|
74
|
+
tslib_1.__param(1, (0, type_graphql_1.Ctx)()),
|
|
75
|
+
tslib_1.__metadata("design:type", Function),
|
|
76
|
+
tslib_1.__metadata("design:paramtypes", [company_types_1.CompanyPatch, Object]),
|
|
77
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
78
|
+
], CompanyMutation.prototype, "saveCompany", null);
|
|
79
|
+
tslib_1.__decorate([
|
|
80
|
+
(0, type_graphql_1.Directive)('@privilege(category: "company", privilege: "mutation", domainOwnerGranted: true)'),
|
|
81
|
+
(0, type_graphql_1.Directive)('@auditTarget(kind: "Company", arg: "companyId")'),
|
|
82
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
|
83
|
+
(0, type_graphql_1.Mutation)(returns => attachment_base_1.Attachment, { nullable: true, description: 'To put the seal (직인) on 「우리 회사」, replacing the one it had; no file takes it away' }),
|
|
84
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('companyId')),
|
|
85
|
+
tslib_1.__param(1, (0, type_graphql_1.Arg)('file', type => GraphQLUpload_js_1.default, { nullable: true })),
|
|
86
|
+
tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
|
|
87
|
+
tslib_1.__metadata("design:type", Function),
|
|
88
|
+
tslib_1.__metadata("design:paramtypes", [String, Object, Object]),
|
|
89
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
90
|
+
], CompanyMutation.prototype, "attachCompanySeal", null);
|
|
53
91
|
tslib_1.__decorate([
|
|
54
92
|
(0, type_graphql_1.Directive)('@privilege(category: "company", privilege: "mutation")'),
|
|
55
93
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
@@ -102,7 +140,8 @@ tslib_1.__decorate([
|
|
|
102
140
|
tslib_1.__metadata("design:returntype", Promise)
|
|
103
141
|
], CompanyMutation.prototype, "deleteCompanies", null);
|
|
104
142
|
exports.CompanyMutation = CompanyMutation = tslib_1.__decorate([
|
|
105
|
-
(0, type_graphql_1.Resolver)(company_1.Company)
|
|
143
|
+
(0, type_graphql_1.Resolver)(company_1.Company),
|
|
144
|
+
(0, type_graphql_1.UseMiddleware)(shell_1.SpeakRefusals)
|
|
106
145
|
], CompanyMutation);
|
|
107
146
|
async function createCompany(company, domain, user, tx) {
|
|
108
147
|
const companyRepository = tx ? tx.getRepository(company_1.Company) : (0, shell_1.getRepository)(company_1.Company);
|
|
@@ -138,4 +177,25 @@ async function deleteCompany(id, tx) {
|
|
|
138
177
|
const repository = tx ? tx.getRepository(company_1.Company) : (0, shell_1.getRepository)(company_1.Company);
|
|
139
178
|
return await repository.delete(id);
|
|
140
179
|
}
|
|
180
|
+
/** The words 「우리 회사」 keeps - what a save may set. */
|
|
181
|
+
exports.OUR_COMPANY_FIELDS = ['name', 'representative', 'brn', 'corporateRegistrationNumber', 'address', 'phone'];
|
|
182
|
+
/**
|
|
183
|
+
* Keep this domain's own company: its row, made on the first save. Only the fields of 「우리 회사」 are taken, trimmed;
|
|
184
|
+
* a name is required - a document cannot print a company without one.
|
|
185
|
+
*/
|
|
186
|
+
async function saveOurCompany(patch, domain, user, tx) {
|
|
187
|
+
const repository = tx.getRepository(company_1.Company);
|
|
188
|
+
const current = await (0, our_company_1.ourCompanyOf)(domain, tx);
|
|
189
|
+
const words = {};
|
|
190
|
+
for (const field of exports.OUR_COMPANY_FIELDS) {
|
|
191
|
+
const value = patch[field];
|
|
192
|
+
if (value === undefined)
|
|
193
|
+
continue;
|
|
194
|
+
words[field] = typeof value === 'string' ? value.trim() : value;
|
|
195
|
+
}
|
|
196
|
+
const name = words.name ?? current?.name;
|
|
197
|
+
if (!name)
|
|
198
|
+
throw new shell_1.Refusal('company-name-required', {}, 'a company needs a name');
|
|
199
|
+
return await repository.save({ ...(current ?? { domain, creator: user }), ...words, updater: user });
|
|
200
|
+
}
|
|
141
201
|
//# sourceMappingURL=company-mutation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"company-mutation.js","sourceRoot":"","sources":["../../../server/service/company/company-mutation.ts"],"names":[],"mappings":";;;AAoFA,sCAeC;AAED,sCAYC;AAED,0CAGC;AAED,sCAGC;;AA3HD,+CAAsE;AAItE,iDAA6D;AAC7D,iDAA+C;AAE/C,uCAAmC;AACnC,mDAA0D;AAGnD,IAAM,eAAe,GAArB,MAAM,eAAe;IAIpB,AAAN,KAAK,CAAC,aAAa,CAAiB,OAAmB,EAAS,OAAwB;QACtF,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAC1C,OAAO,MAAM,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;IACvD,CAAC;IAKK,AAAN,KAAK,CAAC,aAAa,CACJ,IAAY,EACX,KAAmB,EAC1B,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAC1C,OAAO,MAAM,aAAa,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;IAC3D,CAAC;IAKK,AAAN,KAAK,CAAC,qBAAqB,CACe,OAAuB,EACxD,OAAwB;QAE/B,IAAI,OAAO,GAAG,EAAE,CAAA;QAChB,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,KAAU,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,GAAG,CAAC,CAAA;QACzF,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,KAAU,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,GAAG,CAAC,CAAA;QAEzF,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9B,K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AAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE;QACzB,IAAI;KACL,CAAC,CAAA;IAEF,OAAO,UAAU,CAAC,IAAI,CAAC;QACrB,GAAG,OAAO;QACV,GAAG,KAAK;QACR,OAAO,EAAE,IAAI;KACd,CAAC,CAAA;AACJ,CAAC;AAEM,KAAK,UAAU,eAAe,CAAC,GAAa,EAAE,EAAkB;IACrE,MAAM,UAAU,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,iBAAO,CAAC,CAAC,CAAC,CAAC,IAAA,qBAAa,EAAC,iBAAO,CAAC,CAAA;IAC1E,OAAO,MAAM,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;AACrC,CAAC;AAEM,KAAK,UAAU,aAAa,CAAC,EAAU,EAAE,EAAkB;IAChE,MAAM,UAAU,GAAwB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,iBAAO,CAAC,CAAC,CAAC,CAAC,IAAA,qBAAa,EAAC,iBAAO,CAAC,CAAA;IAC/F,OAAO,MAAM,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;AACpC,CAAC","sourcesContent":["import { Arg, Ctx, Directive, Mutation, Resolver } from 'type-graphql'\nimport { EntityManager, Repository } from 'typeorm'\n\nimport { User } from '@things-factory/auth-base'\nimport { Domain, getRepository } from '@things-factory/shell'\nimport { slugger } from '@things-factory/utils'\n\nimport { Company } from './company'\nimport { CompanyPatch, NewCompany } from './company-types'\n\n@Resolver(Company)\nexport class CompanyMutation {\n @Directive('@privilege(category: \"company\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Company)\n async createCompany(@Arg('company') company: NewCompany, @Ctx() context: ResolverContext): Promise<Company> {\n const { domain, user, tx } = context.state\n return await createCompany(company, domain, user, tx)\n }\n\n @Directive('@privilege(category: \"company\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Company)\n async updateCompany(\n @Arg('name') name: string,\n @Arg('patch') patch: CompanyPatch,\n @Ctx() context: ResolverContext\n ): Promise<Company> {\n const { domain, user, tx } = context.state\n return await updateCompany(name, patch, domain, user, tx)\n }\n\n @Directive('@privilege(category: \"company\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => [Company])\n async updateMultipleCompany(\n @Arg('patches', type => [CompanyPatch]) patches: CompanyPatch[],\n @Ctx() context: ResolverContext\n ) {\n let results = []\n const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')\n const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const patch: CompanyPatch = _createRecords[i]\n const result = await this.createCompany(patch as NewCompany, context)\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const patch: CompanyPatch = _updateRecords[i]\n const result = await this.updateCompany(patch.name, patch, context)\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@privilege(category: \"company\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Boolean)\n async deleteCompany(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Boolean> {\n await deleteCompany(id, context.state.tx)\n\n return true\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"company\", privilege: \"mutation\")')\n @Mutation(returns => Boolean)\n async deleteCompanies(\n @Arg('ids', type => [String]) ids: string[],\n @Ctx() context: ResolverContext\n ): Promise<Boolean> {\n await deleteCompanies(ids, context.state.tx)\n\n return true\n }\n}\n\nexport async function createCompany(company: NewCompany, domain: Domain, user: User, tx?: EntityManager) {\n const companyRepository: Repository<Company> = tx ? tx.getRepository(Company) : getRepository(Company)\n const domainRepository: Repository<Domain> = tx ? tx.getRepository(Domain) : getRepository(Domain)\n\n const companyDomain: Domain = await domainRepository.save({\n subdomain: slugger(company.name),\n name: company.name\n })\n\n return await companyRepository.save({\n ...company,\n domain: companyDomain,\n creator: user,\n updater: user\n })\n}\n\nexport async function updateCompany(name: string, patch: CompanyPatch, domain: Domain, user: User, tx?: EntityManager) {\n const repository: Repository<Company> = tx ? tx.getRepository(Company) : getRepository(Company)\n const company = await repository.findOneBy({\n domain: { id: domain.id },\n name\n })\n\n return repository.save({\n ...company,\n ...patch,\n updater: user\n })\n}\n\nexport async function deleteCompanies(ids: string[], tx?: EntityManager) {\n const repository = tx ? tx.getRepository(Company) : getRepository(Company)\n return await repository.delete(ids)\n}\n\nexport async function deleteCompany(id: string, tx?: EntityManager) {\n const repository: Repository<Company> = tx ? tx.getRepository(Company) : getRepository(Company)\n return await repository.delete(id)\n}\n"]}
|
|
1
|
+
{"version":3,"file":"company-mutation.js","sourceRoot":"","sources":["../../../server/service/company/company-mutation.ts"],"names":[],"mappings":";;;AAiHA,sCAeC;AAED,sCAYC;AAED,0CAGC;AAED,sCAGC;AASD,wCAYC;;AA5KD,+FAA2D;AAC3D,+CAAqF;AAGrF,qEAA+E;AAE/E,iDAAqF;AACrF,iDAA+C;AAE/C,uCAAmC;AACnC,mDAA0D;AAC1D,+CAAmE;AAI5D,IAAM,eAAe,GAArB,MAAM,eAAe;IAKpB,AAAN,KAAK,CAAC,WAAW,CAAiB,OAAqB,EAAS,OAAwB;QACtF,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAC1C,OAAO,MAAM,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;IACxD,CAAC;IAMK,AAAN,KAAK,CAAC,iBAAiB,CACH,SAAiB,EACqB,IAAuB,EACxE,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QACpC,MAAM,OAAO,GAAG,MAAM,IAAA,0BAAY,EAAC,MAAM,EAAE,EAAE,CAAC,CAAA;QAC9C,IAAI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C,CAAA;IACnF,OAAO,MAAM,UAAU,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,IAAI,EAAa,CAAC,CAAA;AACjH,CAAC","sourcesContent":["import type { FileUpload } from 'graphql-upload/GraphQLUpload.js'\nimport GraphQLUpload from 'graphql-upload/GraphQLUpload.js'\nimport { Arg, Ctx, Directive, Mutation, Resolver, UseMiddleware } from 'type-graphql'\nimport { EntityManager, Repository } from 'typeorm'\n\nimport { Attachment, replaceAttachment } from '@things-factory/attachment-base'\nimport { User } from '@things-factory/auth-base'\nimport { Domain, getRepository, Refusal, SpeakRefusals } from '@things-factory/shell'\nimport { slugger } from '@things-factory/utils'\n\nimport { Company } from './company'\nimport { CompanyPatch, NewCompany } from './company-types'\nimport { COMPANY_SEAL_REF_TYPE, ourCompanyOf } from './our-company'\n\n@Resolver(Company)\n@UseMiddleware(SpeakRefusals)\nexport class CompanyMutation {\n @Directive('@privilege(category: \"company\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Directive('@auditTarget(kind: \"Company\", arg: \"company\")')\n @Directive('@transaction')\n @Mutation(returns => Company, { description: \"To keep 「우리 회사」 - this domain's own company, made on its first save (ADR-0176)\" })\n async saveCompany(@Arg('company') company: CompanyPatch, @Ctx() context: ResolverContext): Promise<Company> {\n const { domain, user, tx } = context.state\n return await saveOurCompany(company, domain, user, tx)\n }\n\n @Directive('@privilege(category: \"company\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Directive('@auditTarget(kind: \"Company\", arg: \"companyId\")')\n @Directive('@transaction')\n @Mutation(returns => Attachment, { nullable: true, description: 'To put the seal (직인) on 「우리 회사」, replacing the one it had; no file takes it away' })\n async attachCompanySeal(\n @Arg('companyId') companyId: string,\n @Arg('file', type => GraphQLUpload, { nullable: true }) file: FileUpload | null,\n @Ctx() context: ResolverContext\n ): Promise<Attachment | null> {\n const { domain, tx } = context.state\n const company = await ourCompanyOf(domain, tx)\n if (!company || company.id !== companyId) throw new Refusal('company-not-found', {}, 'save the company first')\n return await replaceAttachment({ file, refType: COMPANY_SEAL_REF_TYPE, refBy: company.id, category: 'seal' }, context)\n }\n\n @Directive('@privilege(category: \"company\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Company)\n async createCompany(@Arg('company') company: NewCompany, @Ctx() context: ResolverContext): Promise<Company> {\n const { domain, user, tx } = context.state\n return await createCompany(company, domain, user, tx)\n }\n\n @Directive('@privilege(category: \"company\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Company)\n async updateCompany(\n @Arg('name') name: string,\n @Arg('patch') patch: CompanyPatch,\n @Ctx() context: ResolverContext\n ): Promise<Company> {\n const { domain, user, tx } = context.state\n return await updateCompany(name, patch, domain, user, tx)\n }\n\n @Directive('@privilege(category: \"company\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => [Company])\n async updateMultipleCompany(\n @Arg('patches', type => [CompanyPatch]) patches: CompanyPatch[],\n @Ctx() context: ResolverContext\n ) {\n let results = []\n const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')\n const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const patch: CompanyPatch = _createRecords[i]\n const result = await this.createCompany(patch as NewCompany, context)\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const patch: CompanyPatch = _updateRecords[i]\n const result = await this.updateCompany(patch.name, patch, context)\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@privilege(category: \"company\", privilege: \"mutation\")')\n @Directive('@transaction')\n @Mutation(returns => Boolean)\n async deleteCompany(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Boolean> {\n await deleteCompany(id, context.state.tx)\n\n return true\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"company\", privilege: \"mutation\")')\n @Mutation(returns => Boolean)\n async deleteCompanies(\n @Arg('ids', type => [String]) ids: string[],\n @Ctx() context: ResolverContext\n ): Promise<Boolean> {\n await deleteCompanies(ids, context.state.tx)\n\n return true\n }\n}\n\nexport async function createCompany(company: NewCompany, domain: Domain, user: User, tx?: EntityManager) {\n const companyRepository: Repository<Company> = tx ? tx.getRepository(Company) : getRepository(Company)\n const domainRepository: Repository<Domain> = tx ? tx.getRepository(Domain) : getRepository(Domain)\n\n const companyDomain: Domain = await domainRepository.save({\n subdomain: slugger(company.name),\n name: company.name\n })\n\n return await companyRepository.save({\n ...company,\n domain: companyDomain,\n creator: user,\n updater: user\n })\n}\n\nexport async function updateCompany(name: string, patch: CompanyPatch, domain: Domain, user: User, tx?: EntityManager) {\n const repository: Repository<Company> = tx ? tx.getRepository(Company) : getRepository(Company)\n const company = await repository.findOneBy({\n domain: { id: domain.id },\n name\n })\n\n return repository.save({\n ...company,\n ...patch,\n updater: user\n })\n}\n\nexport async function deleteCompanies(ids: string[], tx?: EntityManager) {\n const repository = tx ? tx.getRepository(Company) : getRepository(Company)\n return await repository.delete(ids)\n}\n\nexport async function deleteCompany(id: string, tx?: EntityManager) {\n const repository: Repository<Company> = tx ? tx.getRepository(Company) : getRepository(Company)\n return await repository.delete(id)\n}\n\n/** The words 「우리 회사」 keeps - what a save may set. */\nexport const OUR_COMPANY_FIELDS = ['name', 'representative', 'brn', 'corporateRegistrationNumber', 'address', 'phone'] as const\n\n/**\n * Keep this domain's own company: its row, made on the first save. Only the fields of 「우리 회사」 are taken, trimmed;\n * a name is required - a document cannot print a company without one.\n */\nexport async function saveOurCompany(patch: Partial<Company>, domain: Domain, user: User, tx: EntityManager): Promise<Company> {\n const repository = tx.getRepository(Company)\n const current = await ourCompanyOf(domain, tx)\n const words: Partial<Company> = {}\n for (const field of OUR_COMPANY_FIELDS) {\n const value = patch[field]\n if (value === undefined) continue\n words[field] = typeof value === 'string' ? value.trim() : value\n }\n const name = words.name ?? current?.name\n if (!name) throw new Refusal('company-name-required', {}, 'a company needs a name')\n return await repository.save({ ...(current ?? { domain, creator: user }), ...words, updater: user } as Company)\n}\n"]}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { Attachment } from '@things-factory/attachment-base';
|
|
1
2
|
import { UserList } from '@things-factory/auth-base';
|
|
2
3
|
import { ListParam } from '@things-factory/shell';
|
|
3
4
|
import { BizplaceList } from '../bizplace/bizplace-types';
|
|
4
5
|
import { Company } from './company';
|
|
5
6
|
import { CompanyList } from './company-types';
|
|
6
7
|
export declare class CompanyQuery {
|
|
7
|
-
company(context: ResolverContext): Promise<Company>;
|
|
8
|
+
company(context: ResolverContext): Promise<Company | null>;
|
|
9
|
+
seal(company: Company): Promise<Attachment | null>;
|
|
8
10
|
companies(params: ListParam, context: ResolverContext): Promise<CompanyList>;
|
|
9
11
|
companyBizplaces(context: ResolverContext): Promise<BizplaceList>;
|
|
10
12
|
companyUsers(context: ResolverContext): Promise<UserList>;
|
|
@@ -4,21 +4,20 @@ exports.CompanyQuery = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const type_graphql_1 = require("type-graphql");
|
|
6
6
|
const typeorm_1 = require("typeorm");
|
|
7
|
+
const attachment_base_1 = require("@things-factory/attachment-base");
|
|
7
8
|
const auth_base_1 = require("@things-factory/auth-base");
|
|
8
9
|
const shell_1 = require("@things-factory/shell");
|
|
9
10
|
const bizplace_1 = require("../bizplace/bizplace");
|
|
10
11
|
const bizplace_types_1 = require("../bizplace/bizplace-types");
|
|
11
12
|
const company_1 = require("./company");
|
|
12
13
|
const company_types_1 = require("./company-types");
|
|
14
|
+
const our_company_1 = require("./our-company");
|
|
13
15
|
let CompanyQuery = class CompanyQuery {
|
|
14
16
|
async company(context) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (!foundCompany)
|
|
20
|
-
throw new Error(context.t('error.no x found', { x: context.t('field.company') }));
|
|
21
|
-
return foundCompany;
|
|
17
|
+
return await (0, our_company_1.ourCompanyOf)(context.state.domain);
|
|
18
|
+
}
|
|
19
|
+
async seal(company) {
|
|
20
|
+
return await (0, our_company_1.companySealOf)(company);
|
|
22
21
|
}
|
|
23
22
|
async companies(params, context) {
|
|
24
23
|
const { domain } = context.state;
|
|
@@ -53,12 +52,20 @@ let CompanyQuery = class CompanyQuery {
|
|
|
53
52
|
exports.CompanyQuery = CompanyQuery;
|
|
54
53
|
tslib_1.__decorate([
|
|
55
54
|
(0, type_graphql_1.Directive)('@privilege(category: "company", privilege: "query", domainOwnerGranted: true)'),
|
|
56
|
-
(0, type_graphql_1.Query)(returns => company_1.Company),
|
|
55
|
+
(0, type_graphql_1.Query)(returns => company_1.Company, { nullable: true, description: '「우리 회사」 - this domain\'s own company, or none yet (ADR-0176)' }),
|
|
57
56
|
tslib_1.__param(0, (0, type_graphql_1.Ctx)()),
|
|
58
57
|
tslib_1.__metadata("design:type", Function),
|
|
59
58
|
tslib_1.__metadata("design:paramtypes", [Object]),
|
|
60
59
|
tslib_1.__metadata("design:returntype", Promise)
|
|
61
60
|
], CompanyQuery.prototype, "company", null);
|
|
61
|
+
tslib_1.__decorate([
|
|
62
|
+
(0, type_graphql_1.Directive)('@privilege(category: "company", privilege: "query", domainOwnerGranted: true)'),
|
|
63
|
+
(0, type_graphql_1.FieldResolver)(type => attachment_base_1.Attachment, { nullable: true, description: 'The seal (직인) official documents print' }),
|
|
64
|
+
tslib_1.__param(0, (0, type_graphql_1.Root)()),
|
|
65
|
+
tslib_1.__metadata("design:type", Function),
|
|
66
|
+
tslib_1.__metadata("design:paramtypes", [company_1.Company]),
|
|
67
|
+
tslib_1.__metadata("design:returntype", Promise)
|
|
68
|
+
], CompanyQuery.prototype, "seal", null);
|
|
62
69
|
tslib_1.__decorate([
|
|
63
70
|
(0, type_graphql_1.Directive)('@privilege(category: "company", privilege: "query")'),
|
|
64
71
|
(0, type_graphql_1.Query)(returns => company_types_1.CompanyList),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"company-query.js","sourceRoot":"","sources":["../../../server/service/company/company-query.ts"],"names":[],"mappings":";;;;AAAA,+
|
|
1
|
+
{"version":3,"file":"company-query.js","sourceRoot":"","sources":["../../../server/service/company/company-query.ts"],"names":[],"mappings":";;;;AAAA,+CAAyF;AACzF,qCAA4B;AAE5B,qEAA4D;AAC5D,yDAA0F;AAC1F,iDAA2F;AAE3F,mDAA+C;AAC/C,+DAAyD;AACzD,uCAAmC;AACnC,mDAA6C;AAC7C,+CAA2D;AAGpD,IAAM,YAAY,GAAlB,MAAM,YAAY;IAGjB,AAAN,KAAK,CAAC,OAAO,CAAQ,OAAwB;QAC3C,OAAO,MAAM,IAAA,0BAAY,EAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IACjD,CAAC;IAIK,AAAN,KAAK,CAAC,IAAI,CAAS,OAAgB;QACjC,OAAO,MAAM,IAAA,2BAAa,EAAC,OAAO,CAAC,CAAA;IACrC,CAAC;IAIK,AAAN,KAAK,CAAC,SAAS,CAA0B,MAAiB,EAAS,OAAwB;QACzF,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAChC,MAAM,eAAe,GAAG,IAAA,yBAAiB,EAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAA;QAE7D,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,MAAM,IAAA,qBAAa,EAAC,iBAAO,CAAC,CAAC,YAAY,CAAC;YAC/D,GAAG,eAAe;YAClB,SAAS,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,CAAC;SAC5C,CAAC,CAAA;QACF,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;IACzB,CAAC;IAIK,AAAN,KAAK,CAAC,gBAAgB,CAAQ,OAAwB;QACpD,MAAM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AA;;;;2CAEnB;AAIK;IAFL,IAAA,wBAAS,EAAC,+EAA+E,CAAC;IAC1F,IAAA,4BAAa,EAAC,IAAI,CAAC,EAAE,CAAC,4BAAU,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,wCAAwC,EAAE,CAAC;IACjG,mBAAA,IAAA,mBAAI,GAAE,CAAA;;6CAAU,iBAAO;;wCAElC;AAIK;IAFL,IAAA,wBAAS,EAAC,qDAAqD,CAAC;IAChE,IAAA,oBAAK,EAAC,OAAO,CAAC,EAAE,CAAC,2BAAW,CAAC;IACb,mBAAA,IAAA,mBAAI,EAAC,IAAI,CAAC,EAAE,CAAC,iBAAS,CAAC,CAAA;IAAqB,mBAAA,IAAA,kBAAG,GAAE,CAAA;;6CAAjB,iBAAS;;6CASzD;AAIK;IAFL,IAAA,wBAAS,EAAC,+EAA+E,CAAC;IAC1F,IAAA,oBAAK,EAAC,OAAO,CAAC,EAAE,CAAC,6BAAY,CAAC;IACP,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;oDAc5B;AAIK;IAFL,IAAA,wBAAS,EAAC,+EAA+E,CAAC;IAC1F,IAAA,oBAAK,EAAC,OAAO,CAAC,EAAE,CAAC,oBAAQ,CAAC;IACP,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;gDASxB;uBAvDU,YAAY;IADxB,IAAA,uBAAQ,EAAC,iBAAO,CAAC;GACL,YAAY,CAwDxB","sourcesContent":["import { Args, Ctx, Directive, FieldResolver, Query, Resolver, Root } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { Attachment } from '@things-factory/attachment-base'\nimport { getDomainUsers, getUserDomains, User, UserList } from '@things-factory/auth-base'\nimport { convertListParams, Domain, getRepository, ListParam } from '@things-factory/shell'\n\nimport { Bizplace } from '../bizplace/bizplace'\nimport { BizplaceList } from '../bizplace/bizplace-types'\nimport { Company } from './company'\nimport { CompanyList } from './company-types'\nimport { companySealOf, ourCompanyOf } from './our-company'\n\n@Resolver(Company)\nexport class CompanyQuery {\n @Directive('@privilege(category: \"company\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => Company, { nullable: true, description: '「우리 회사」 - this domain\\'s own company, or none yet (ADR-0176)' })\n async company(@Ctx() context: ResolverContext): Promise<Company | null> {\n return await ourCompanyOf(context.state.domain)\n }\n\n @Directive('@privilege(category: \"company\", privilege: \"query\", domainOwnerGranted: true)')\n @FieldResolver(type => Attachment, { nullable: true, description: 'The seal (직인) official documents print' })\n async seal(@Root() company: Company): Promise<Attachment | null> {\n return await companySealOf(company)\n }\n\n @Directive('@privilege(category: \"company\", privilege: \"query\")')\n @Query(returns => CompanyList)\n async companies(@Args(type => ListParam) params: ListParam, @Ctx() context: ResolverContext): Promise<CompanyList> {\n const { domain } = context.state\n const convertedParams = convertListParams(params, { domain })\n\n const [items, total] = await getRepository(Company).findAndCount({\n ...convertedParams,\n relations: ['domain', 'creator', 'updater']\n })\n return { items, total }\n }\n\n @Directive('@privilege(category: \"company\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => BizplaceList)\n async companyBizplaces(@Ctx() context: ResolverContext): Promise<BizplaceList> {\n const { domain, user } = context.state\n\n const userDomains: Partial<Domain>[] = await getUserDomains(user)\n const company: Company = await getRepository(Company).findOneBy({\n domain: { id: domain.id }\n })\n\n const [items, total] = await getRepository(Bizplace).findAndCount({\n where: { company: { id: company.id }, domain: { id: In(userDomains.map(({ id }: Domain) => id)) } },\n relations: ['domain']\n })\n\n return { items, total }\n }\n\n @Directive('@privilege(category: \"company\", privilege: \"query\", domainOwnerGranted: true)')\n @Query(returns => UserList)\n async companyUsers(@Ctx() context: ResolverContext): Promise<UserList> {\n const { domain } = context.state\n\n const items: User[] = await getDomainUsers(domain)\n\n return {\n items,\n total: items.length\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { checkPermission } from '@things-factory/auth-base';
|
|
2
|
+
/**
|
|
3
|
+
* Who may open the company's seal by its attachment path (ADR-0176 decision 4): whoever keeps the company - the
|
|
4
|
+
* settings card shows them a preview. Everyone else meets the seal only printed on a document.
|
|
5
|
+
*/
|
|
6
|
+
export declare function companySealReader(_attachment: unknown, context: any, check?: typeof checkPermission): Promise<boolean>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.companySealReader = companySealReader;
|
|
4
|
+
const attachment_base_1 = require("@things-factory/attachment-base");
|
|
5
|
+
const auth_base_1 = require("@things-factory/auth-base");
|
|
6
|
+
const our_company_1 = require("./our-company");
|
|
7
|
+
/**
|
|
8
|
+
* Who may open the company's seal by its attachment path (ADR-0176 decision 4): whoever keeps the company - the
|
|
9
|
+
* settings card shows them a preview. Everyone else meets the seal only printed on a document.
|
|
10
|
+
*/
|
|
11
|
+
async function companySealReader(_attachment, context, check = auth_base_1.checkPermission) {
|
|
12
|
+
const { domain, user, unsafeIP, prohibitedPrivileges } = context?.state ?? {};
|
|
13
|
+
return !!(await check({ category: 'company', privilege: 'mutation', owner: true }, user, domain, unsafeIP, prohibitedPrivileges));
|
|
14
|
+
}
|
|
15
|
+
(0, attachment_base_1.registerAttachmentReader)(our_company_1.COMPANY_SEAL_REF_TYPE, (attachment, context) => companySealReader(attachment, context));
|
|
16
|
+
//# sourceMappingURL=company-seal-reader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"company-seal-reader.js","sourceRoot":"","sources":["../../../server/service/company/company-seal-reader.ts"],"names":[],"mappings":";;AASA,8CAGC;AAZD,qEAA0E;AAC1E,yDAA2D;AAE3D,+CAAqD;AAErD;;;GAGG;AACI,KAAK,UAAU,iBAAiB,CAAC,WAAoB,EAAE,OAAY,EAAE,QAAgC,2BAAe;IACzH,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,oBAAoB,EAAE,GAAG,OAAO,EAAE,KAAK,IAAI,EAAE,CAAA;IAC7E,OAAO,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,oBAAoB,CAAC,CAAC,CAAA;AACnI,CAAC;AAED,IAAA,0CAAwB,EAAC,mCAAqB,EAAE,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE,CAAC,iBAAiB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,CAAA","sourcesContent":["import { registerAttachmentReader } from '@things-factory/attachment-base'\nimport { checkPermission } from '@things-factory/auth-base'\n\nimport { COMPANY_SEAL_REF_TYPE } from './our-company'\n\n/**\n * Who may open the company's seal by its attachment path (ADR-0176 decision 4): whoever keeps the company - the\n * settings card shows them a preview. Everyone else meets the seal only printed on a document.\n */\nexport async function companySealReader(_attachment: unknown, context: any, check: typeof checkPermission = checkPermission): Promise<boolean> {\n const { domain, user, unsafeIP, prohibitedPrivileges } = context?.state ?? {}\n return !!(await check({ category: 'company', privilege: 'mutation', owner: true }, user, domain, unsafeIP, prohibitedPrivileges))\n}\n\nregisterAttachmentReader(COMPANY_SEAL_REF_TYPE, (attachment, context) => companySealReader(attachment, context))\n"]}
|
|
@@ -49,6 +49,18 @@ tslib_1.__decorate([
|
|
|
49
49
|
(0, type_graphql_1.Field)({ nullable: true }),
|
|
50
50
|
tslib_1.__metadata("design:type", String)
|
|
51
51
|
], CompanyPatch.prototype, "postalCode", void 0);
|
|
52
|
+
tslib_1.__decorate([
|
|
53
|
+
(0, type_graphql_1.Field)({ nullable: true }),
|
|
54
|
+
tslib_1.__metadata("design:type", String)
|
|
55
|
+
], CompanyPatch.prototype, "corporateRegistrationNumber", void 0);
|
|
56
|
+
tslib_1.__decorate([
|
|
57
|
+
(0, type_graphql_1.Field)({ nullable: true }),
|
|
58
|
+
tslib_1.__metadata("design:type", String)
|
|
59
|
+
], CompanyPatch.prototype, "representative", void 0);
|
|
60
|
+
tslib_1.__decorate([
|
|
61
|
+
(0, type_graphql_1.Field)({ nullable: true }),
|
|
62
|
+
tslib_1.__metadata("design:type", String)
|
|
63
|
+
], CompanyPatch.prototype, "phone", void 0);
|
|
52
64
|
tslib_1.__decorate([
|
|
53
65
|
(0, type_graphql_1.Field)({ nullable: true }),
|
|
54
66
|
tslib_1.__metadata("design:type", String)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"company-types.js","sourceRoot":"","sources":["../../../server/service/company/company-types.ts"],"names":[],"mappings":";;;;AAAA,+CAAgE;AAChE,uCAAmC;AAG5B,IAAM,WAAW,GAAjB,MAAM,WAAW;CAMvB,CAAA;AANY,kCAAW;AAEtB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,iBAAO,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;0CAC5B;AAGjB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,kBAAG,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;0CACzB;sBALH,WAAW;IADvB,IAAA,yBAAU,GAAE;GACA,WAAW,CAMvB;AAGM,IAAM,YAAY,GAAlB,MAAM,YAAY;
|
|
1
|
+
{"version":3,"file":"company-types.js","sourceRoot":"","sources":["../../../server/service/company/company-types.ts"],"names":[],"mappings":";;;;AAAA,+CAAgE;AAChE,uCAAmC;AAG5B,IAAM,WAAW,GAAjB,MAAM,WAAW;CAMvB,CAAA;AANY,kCAAW;AAEtB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,CAAC,iBAAO,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;0CAC5B;AAGjB;IADC,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,kBAAG,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;0CACzB;sBALH,WAAW;IADvB,IAAA,yBAAU,GAAE;GACA,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ADC,IAAA,oBAAK,GAAE;;+CACW;AAGnB;IADC,IAAA,oBAAK,GAAE;;uCACG;AAGX;IADC,IAAA,oBAAK,GAAE;;2CACO;AAGf;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;8CACR;AAGlB;IADC,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;wCACb;AAGb;IADC,IAAA,oBAAK,GAAE;;0CACM;qBAvBH,UAAU;IADtB,IAAA,wBAAS,GAAE;GACC,UAAU,CAwBtB","sourcesContent":["import { ObjectType, InputType, Field, Int } from 'type-graphql'\nimport { Company } from './company'\n\n@ObjectType()\nexport class CompanyList {\n @Field(type => [Company], { nullable: true })\n items?: Company[]\n\n @Field(type => Int, { nullable: true })\n total?: number\n}\n\n@InputType()\nexport class CompanyPatch {\n @Field({ nullable: true })\n id?: string\n\n @Field({ nullable: true })\n name?: string\n\n @Field({ nullable: true })\n description?: string\n\n @Field({ nullable: true })\n countryCode?: string\n\n @Field({ nullable: true })\n brn?: string\n\n @Field({ nullable: true })\n address?: string\n\n @Field({ nullable: true })\n postalCode?: string\n\n @Field({ nullable: true })\n corporateRegistrationNumber?: string\n\n @Field({ nullable: true })\n representative?: string\n\n @Field({ nullable: true })\n phone?: string\n\n @Field({ nullable: true })\n status?: string\n\n @Field({ nullable: true })\n cuFlag?: string\n}\n\n@InputType()\nexport class NewCompany {\n @Field()\n name: string\n\n @Field({ nullable: true })\n description?: string\n\n @Field()\n countryCode: string\n\n @Field()\n brn: string\n\n @Field()\n address: string\n\n @Field({ nullable: true })\n postalCode: string\n\n @Field({ nullable: true })\n type?: string\n\n @Field()\n status: string\n}\n"]}
|
|
@@ -9,7 +9,10 @@ export declare class Company {
|
|
|
9
9
|
description: string;
|
|
10
10
|
countryCode: string;
|
|
11
11
|
brn: string;
|
|
12
|
+
corporateRegistrationNumber: string;
|
|
13
|
+
representative: string;
|
|
12
14
|
address: string;
|
|
15
|
+
phone: string;
|
|
13
16
|
postalCode: string;
|
|
14
17
|
type: string;
|
|
15
18
|
status: string;
|
|
@@ -7,6 +7,11 @@ const typeorm_1 = require("typeorm");
|
|
|
7
7
|
const auth_base_1 = require("@things-factory/auth-base");
|
|
8
8
|
const shell_1 = require("@things-factory/shell");
|
|
9
9
|
const bizplace_1 = require("../bizplace/bizplace");
|
|
10
|
+
/*
|
|
11
|
+
* A company and, for a domain, 「우리 회사」 (ADR-0176 decision 4): the one place its name, representative, registration
|
|
12
|
+
* numbers, address, phone and seal are kept. Quotations, invoices, pay slips and every official document read them from
|
|
13
|
+
* here (`our-company.ts`); the seal is an attachment of the row (`COMPANY_SEAL_REF_TYPE`).
|
|
14
|
+
*/
|
|
10
15
|
let Company = class Company {
|
|
11
16
|
};
|
|
12
17
|
exports.Company = Company;
|
|
@@ -38,20 +43,35 @@ tslib_1.__decorate([
|
|
|
38
43
|
tslib_1.__metadata("design:type", String)
|
|
39
44
|
], Company.prototype, "description", void 0);
|
|
40
45
|
tslib_1.__decorate([
|
|
41
|
-
(0, typeorm_1.Column)(),
|
|
42
|
-
(0, type_graphql_1.Field)(),
|
|
46
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
47
|
+
(0, type_graphql_1.Field)({ nullable: true }),
|
|
43
48
|
tslib_1.__metadata("design:type", String)
|
|
44
49
|
], Company.prototype, "countryCode", void 0);
|
|
45
50
|
tslib_1.__decorate([
|
|
46
|
-
(0, typeorm_1.Column)(),
|
|
47
|
-
(0, type_graphql_1.Field)(),
|
|
51
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
52
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'Business registration number (사업자등록번호)' }),
|
|
48
53
|
tslib_1.__metadata("design:type", String)
|
|
49
54
|
], Company.prototype, "brn", void 0);
|
|
50
55
|
tslib_1.__decorate([
|
|
51
|
-
(0, typeorm_1.Column)(),
|
|
52
|
-
(0, type_graphql_1.Field)(),
|
|
56
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
57
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'Corporate registration number (법인등록번호)' }),
|
|
58
|
+
tslib_1.__metadata("design:type", String)
|
|
59
|
+
], Company.prototype, "corporateRegistrationNumber", void 0);
|
|
60
|
+
tslib_1.__decorate([
|
|
61
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
62
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'The representative (대표자) as printed on official documents' }),
|
|
63
|
+
tslib_1.__metadata("design:type", String)
|
|
64
|
+
], Company.prototype, "representative", void 0);
|
|
65
|
+
tslib_1.__decorate([
|
|
66
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
67
|
+
(0, type_graphql_1.Field)({ nullable: true }),
|
|
53
68
|
tslib_1.__metadata("design:type", String)
|
|
54
69
|
], Company.prototype, "address", void 0);
|
|
70
|
+
tslib_1.__decorate([
|
|
71
|
+
(0, typeorm_1.Column)({ nullable: true }),
|
|
72
|
+
(0, type_graphql_1.Field)({ nullable: true, description: 'The main phone number (대표 전화)' }),
|
|
73
|
+
tslib_1.__metadata("design:type", String)
|
|
74
|
+
], Company.prototype, "phone", void 0);
|
|
55
75
|
tslib_1.__decorate([
|
|
56
76
|
(0, typeorm_1.Column)({
|
|
57
77
|
nullable: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"company.js","sourceRoot":"","sources":["../../../server/service/company/company.ts"],"names":[],"mappings":";;;;AAAA,+CAAoD;AACpD,qCAUgB;AAEhB,yDAAgD;AAChD,iDAA8C;AAE9C,mDAA+C;
|
|
1
|
+
{"version":3,"file":"company.js","sourceRoot":"","sources":["../../../server/service/company/company.ts"],"names":[],"mappings":";;;;AAAA,+CAAoD;AACpD,qCAUgB;AAEhB,yDAAgD;AAChD,iDAA8C;AAE9C,mDAA+C;AAE/C;;;;GAIG;AAKI,IAAM,OAAO,GAAb,MAAM,OAAO;CAgGnB,CAAA;AAhGY,0BAAO;AAGT;IAFR,IAAA,gCAAs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BAAS,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,EAAE;QACvB,QAAQ,EAAE,IAAI;KACf,CAAC;IACD,IAAA,oBAAK,EAAC,IAAI,CAAC,EAAE,CAAC,gBAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;sCAC/B,gBAAI;wCAAA;AAGb;IADC,IAAA,oBAAU,EAAC,CAAC,OAAgB,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC;;0CACjC;AAIjB;IAFC,IAAA,0BAAgB,GAAE;IAClB,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;sCACf,IAAI;0CAAA;AAIf;IAFC,IAAA,0BAAgB,GAAE;IAClB,IAAA,oBAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;sCACf,IAAI;0CAAA;kBA/FJ,OAAO;IAJnB,IAAA,gBAAM,GAAE;IACR,IAAA,eAAK,EAAC,gBAAgB,EAAE,CAAC,OAAgB,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAC/E,IAAA,eAAK,EAAC,gBAAgB,EAAE,CAAC,OAAgB,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;IAClF,IAAA,yBAAU,GAAE;GACA,OAAO,CAgGnB","sourcesContent":["import { Field, ID, ObjectType } from 'type-graphql'\nimport {\n Column,\n CreateDateColumn,\n Entity,\n Index,\n ManyToOne,\n OneToMany,\n PrimaryGeneratedColumn,\n RelationId,\n UpdateDateColumn\n} from 'typeorm'\n\nimport { User } from '@things-factory/auth-base'\nimport { Domain } from '@things-factory/shell'\n\nimport { Bizplace } from '../bizplace/bizplace'\n\n/*\n * A company and, for a domain, 「우리 회사」 (ADR-0176 decision 4): the one place its name, representative, registration\n * numbers, address, phone and seal are kept. Quotations, invoices, pay slips and every official document read them from\n * here (`our-company.ts`); the seal is an attachment of the row (`COMPANY_SEAL_REF_TYPE`).\n */\n@Entity()\n@Index('ix_companies_0', (company: Company) => [company.name], { unique: true })\n@Index('ix_companies_1', (company: Company) => [company.domain], { unique: false })\n@ObjectType()\nexport class Company {\n @PrimaryGeneratedColumn('uuid')\n @Field(type => ID)\n readonly id: string\n\n @ManyToOne(type => Domain)\n @Field(type => Domain)\n domain?: Domain\n\n @RelationId((company: Company) => company.domain)\n @Field()\n domainId: string\n\n @Column()\n @Field()\n name: string\n\n @Column({\n nullable: true\n })\n @Field({ nullable: true })\n description: string\n\n @Column({ nullable: true })\n @Field({ nullable: true })\n countryCode: string\n\n /* 사업자등록번호 */\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'Business registration number (사업자등록번호)' })\n brn: string\n\n /* 법인등록번호 */\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'Corporate registration number (법인등록번호)' })\n corporateRegistrationNumber: string\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'The representative (대표자) as printed on official documents' })\n representative: string\n\n @Column({ nullable: true })\n @Field({ nullable: true })\n address: string\n\n @Column({ nullable: true })\n @Field({ nullable: true, description: 'The main phone number (대표 전화)' })\n phone: string\n\n @Column({\n nullable: true\n })\n @Field({ nullable: true })\n postalCode: string\n\n @Column({\n nullable: true\n })\n @Field({ nullable: true })\n type: string\n\n @Column({\n nullable: true\n })\n @Field({ nullable: true })\n status: string\n\n @OneToMany(type => Bizplace, bizplace => bizplace.company)\n @Field(type => [Bizplace])\n bizplaces: Bizplace[]\n\n @ManyToOne(type => User, {\n nullable: true\n })\n @Field(type => User, { nullable: true })\n creator: User\n\n @RelationId((company: Company) => company.creator)\n creatorId: string\n\n @ManyToOne(type => User, {\n nullable: true\n })\n @Field(type => User, { nullable: true })\n updater: User\n\n @RelationId((company: Company) => company.updater)\n updaterId: string\n\n @CreateDateColumn()\n @Field({ nullable: true })\n createdAt: Date\n\n @UpdateDateColumn()\n @Field({ nullable: true })\n updatedAt: Date\n}\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Attachment } from '@things-factory/attachment-base';
|
|
2
|
+
import { getRepository } from '@things-factory/shell';
|
|
3
|
+
import { Company } from './company';
|
|
4
|
+
/** The attachment `refType` of the company's seal - read by whoever keeps the company (`company-seal-reader.ts`). */
|
|
5
|
+
export declare const COMPANY_SEAL_REF_TYPE = "Company Seal";
|
|
6
|
+
/** The company as a document prints it. `seal` is a `data:` URL, made on the server only for a print. */
|
|
7
|
+
export interface PrintedCompany {
|
|
8
|
+
name: string;
|
|
9
|
+
representative: string;
|
|
10
|
+
brn: string;
|
|
11
|
+
corporateRegistrationNumber: string;
|
|
12
|
+
address: string;
|
|
13
|
+
phone: string;
|
|
14
|
+
seal?: string;
|
|
15
|
+
}
|
|
16
|
+
type Source = {
|
|
17
|
+
getRepository: typeof getRepository;
|
|
18
|
+
};
|
|
19
|
+
/** This domain's own company row, or none yet. */
|
|
20
|
+
export declare function ourCompanyOf(domain: {
|
|
21
|
+
id: string;
|
|
22
|
+
}, manager?: Source): Promise<Company | null>;
|
|
23
|
+
/** The seal attachment of a company, if one was put on it. */
|
|
24
|
+
export declare function companySealOf(company: {
|
|
25
|
+
id: string;
|
|
26
|
+
} | null, manager?: Source): Promise<Attachment | null>;
|
|
27
|
+
/** The words of a company row as printed - a domain with no row yet prints its own name (`description`, else `name`). */
|
|
28
|
+
export declare function printedWordsOf(company: Partial<Company> | null, domain: {
|
|
29
|
+
name?: string;
|
|
30
|
+
description?: string;
|
|
31
|
+
}): PrintedCompany;
|
|
32
|
+
/**
|
|
33
|
+
* The company as a document prints it. With `seal`, the seal is read from storage into a `data:` URL - for the pdf
|
|
34
|
+
* module's print, whose page loads nothing but what it carries. Never handed to a screen.
|
|
35
|
+
*/
|
|
36
|
+
export declare function printedCompanyOf(domain: {
|
|
37
|
+
id: string;
|
|
38
|
+
name?: string;
|
|
39
|
+
description?: string;
|
|
40
|
+
}, options?: {
|
|
41
|
+
seal?: boolean;
|
|
42
|
+
manager?: Source;
|
|
43
|
+
}): Promise<PrintedCompany>;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.COMPANY_SEAL_REF_TYPE = void 0;
|
|
4
|
+
exports.ourCompanyOf = ourCompanyOf;
|
|
5
|
+
exports.companySealOf = companySealOf;
|
|
6
|
+
exports.printedWordsOf = printedWordsOf;
|
|
7
|
+
exports.printedCompanyOf = printedCompanyOf;
|
|
8
|
+
const attachment_base_1 = require("@things-factory/attachment-base");
|
|
9
|
+
const shell_1 = require("@things-factory/shell");
|
|
10
|
+
const company_1 = require("./company");
|
|
11
|
+
/*
|
|
12
|
+
* 「우리 회사」 (ADR-0176 decision 4) - the company row of a domain, as the documents it writes read it. Quotations,
|
|
13
|
+
* invoices, pay slips and the official documents all print it from here; none keeps a copy of its own.
|
|
14
|
+
*/
|
|
15
|
+
/** The attachment `refType` of the company's seal - read by whoever keeps the company (`company-seal-reader.ts`). */
|
|
16
|
+
exports.COMPANY_SEAL_REF_TYPE = 'Company Seal';
|
|
17
|
+
const sourceOf = (manager) => manager ?? { getRepository: shell_1.getRepository };
|
|
18
|
+
/** This domain's own company row, or none yet. */
|
|
19
|
+
async function ourCompanyOf(domain, manager) {
|
|
20
|
+
return (await sourceOf(manager).getRepository(company_1.Company).findOne({ where: { domain: { id: domain.id } }, order: { createdAt: 'ASC' } })) ?? null;
|
|
21
|
+
}
|
|
22
|
+
/** The seal attachment of a company, if one was put on it. */
|
|
23
|
+
async function companySealOf(company, manager) {
|
|
24
|
+
if (!company)
|
|
25
|
+
return null;
|
|
26
|
+
return (await sourceOf(manager).getRepository(attachment_base_1.Attachment).findOne({ where: { refType: exports.COMPANY_SEAL_REF_TYPE, refBy: company.id }, order: { createdAt: 'DESC' } })) ?? null;
|
|
27
|
+
}
|
|
28
|
+
/** The words of a company row as printed - a domain with no row yet prints its own name (`description`, else `name`). */
|
|
29
|
+
function printedWordsOf(company, domain) {
|
|
30
|
+
const text = (value) => (typeof value === 'string' ? value.trim() : '');
|
|
31
|
+
return {
|
|
32
|
+
name: text(company?.name) || text(domain.description) || text(domain.name),
|
|
33
|
+
representative: text(company?.representative),
|
|
34
|
+
brn: text(company?.brn),
|
|
35
|
+
corporateRegistrationNumber: text(company?.corporateRegistrationNumber),
|
|
36
|
+
address: text(company?.address),
|
|
37
|
+
phone: text(company?.phone)
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The company as a document prints it. With `seal`, the seal is read from storage into a `data:` URL - for the pdf
|
|
42
|
+
* module's print, whose page loads nothing but what it carries. Never handed to a screen.
|
|
43
|
+
*/
|
|
44
|
+
async function printedCompanyOf(domain, options = {}) {
|
|
45
|
+
const company = await ourCompanyOf(domain, options.manager);
|
|
46
|
+
const printed = printedWordsOf(company, domain);
|
|
47
|
+
if (!options.seal)
|
|
48
|
+
return printed;
|
|
49
|
+
const seal = await companySealOf(company, options.manager);
|
|
50
|
+
if (!seal?.path)
|
|
51
|
+
return printed;
|
|
52
|
+
const contents = await attachment_base_1.STORAGE.readFile(seal.path);
|
|
53
|
+
return { ...printed, seal: `data:${seal.mimetype || 'image/png'};base64,${Buffer.from(contents).toString('base64')}` };
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=our-company.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"our-company.js","sourceRoot":"","sources":["../../../server/service/company/our-company.ts"],"names":[],"mappings":";;;AA4BA,oCAEC;AAGD,sCAGC;AAGD,wCAUC;AAMD,4CAQC;AA/DD,qEAAqE;AACrE,iDAAqD;AAErD,uCAAmC;AAEnC;;;GAGG;AAEH,qHAAqH;AACxG,QAAA,qBAAqB,GAAG,cAAc,CAAA;AAcnD,MAAM,QAAQ,GAAG,CAAC,OAAgB,EAAE,EAAE,CAAC,OAAO,IAAI,EAAE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C,OAAO,EAAE,GAAG,CAAC;QACvB,2BAA2B,EAAE,IAAI,CAAC,OAAO,EAAE,2BAA2B,CAAC;QACvE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC;QAC/B,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC;KAC5B,CAAA;AACH,CAAC;AAED;;;GAGG;AACI,KAAK,UAAU,gBAAgB,CAAC,MAA2D,EAAE,UAAgD,EAAE;IACpJ,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IAC3D,MAAM,OAAO,GAAG,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IAC/C,IAAI,CAAC,OAAO,CAAC,IAAI;QAAE,OAAO,OAAO,CAAA;IACjC,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;IAC1D,IAAI,CAAC,IAAI,EAAE,IAAI;QAAE,OAAO,OAAO,CAAA;IAC/B,MAAM,QAAQ,GAAW,MAAM,yBAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC1D,OAAO,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,QAAQ,IAAI,CAAC,QAAQ,IAAI,WAAW,WAAW,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAA;AACxH,CAAC","sourcesContent":["import { Attachment, STORAGE } from '@things-factory/attachment-base'\nimport { getRepository } from '@things-factory/shell'\n\nimport { Company } from './company'\n\n/*\n * 「우리 회사」 (ADR-0176 decision 4) - the company row of a domain, as the documents it writes read it. Quotations,\n * invoices, pay slips and the official documents all print it from here; none keeps a copy of its own.\n */\n\n/** The attachment `refType` of the company's seal - read by whoever keeps the company (`company-seal-reader.ts`). */\nexport const COMPANY_SEAL_REF_TYPE = 'Company Seal'\n\n/** The company as a document prints it. `seal` is a `data:` URL, made on the server only for a print. */\nexport interface PrintedCompany {\n name: string\n representative: string\n brn: string\n corporateRegistrationNumber: string\n address: string\n phone: string\n seal?: string\n}\n\ntype Source = { getRepository: typeof getRepository }\nconst sourceOf = (manager?: Source) => manager ?? { getRepository }\n\n/** This domain's own company row, or none yet. */\nexport async function ourCompanyOf(domain: { id: string }, manager?: Source): Promise<Company | null> {\n return (await sourceOf(manager).getRepository(Company).findOne({ where: { domain: { id: domain.id } }, order: { createdAt: 'ASC' } })) ?? null\n}\n\n/** The seal attachment of a company, if one was put on it. */\nexport async function companySealOf(company: { id: string } | null, manager?: Source): Promise<Attachment | null> {\n if (!company) return null\n return (await sourceOf(manager).getRepository(Attachment).findOne({ where: { refType: COMPANY_SEAL_REF_TYPE, refBy: company.id }, order: { createdAt: 'DESC' } })) ?? null\n}\n\n/** The words of a company row as printed - a domain with no row yet prints its own name (`description`, else `name`). */\nexport function printedWordsOf(company: Partial<Company> | null, domain: { name?: string; description?: string }): PrintedCompany {\n const text = (value: unknown) => (typeof value === 'string' ? value.trim() : '')\n return {\n name: text(company?.name) || text(domain.description) || text(domain.name),\n representative: text(company?.representative),\n brn: text(company?.brn),\n corporateRegistrationNumber: text(company?.corporateRegistrationNumber),\n address: text(company?.address),\n phone: text(company?.phone)\n }\n}\n\n/**\n * The company as a document prints it. With `seal`, the seal is read from storage into a `data:` URL - for the pdf\n * module's print, whose page loads nothing but what it carries. Never handed to a screen.\n */\nexport async function printedCompanyOf(domain: { id: string; name?: string; description?: string }, options: { seal?: boolean; manager?: Source } = {}): Promise<PrintedCompany> {\n const company = await ourCompanyOf(domain, options.manager)\n const printed = printedWordsOf(company, domain)\n if (!options.seal) return printed\n const seal = await companySealOf(company, options.manager)\n if (!seal?.path) return printed\n const contents: Buffer = await STORAGE.readFile(seal.path)\n return { ...printed, seal: `data:${seal.mimetype || 'image/png'};base64,${Buffer.from(contents).toString('base64')}` }\n}\n"]}
|