@things-factory/organization 10.1.104 → 10.1.106
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/ai-entry/organization-entry-targets.js +3 -5
- package/dist-server/ai-entry/organization-entry-targets.js.map +1 -1
- package/dist-server/service/department/department-mutation.js +5 -12
- package/dist-server/service/department/department-mutation.js.map +1 -1
- package/dist-server/service/domain-reference.d.ts +9 -0
- package/dist-server/service/domain-reference.js +48 -0
- package/dist-server/service/domain-reference.js.map +1 -0
- package/dist-server/service/employee/employee-mutation.js +13 -37
- package/dist-server/service/employee/employee-mutation.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/tests/domain-reference.test.ts +184 -0
|
@@ -72,8 +72,7 @@ const DEPARTMENT_FIELDS = [
|
|
|
72
72
|
/* DepartmentPatch has no `extension` - the update changes only what the patch can carry. */
|
|
73
73
|
const DEPARTMENT_UPDATE_FIELDS = ['controlNo', 'name', 'description', 'active', 'parent'];
|
|
74
74
|
/*
|
|
75
|
-
* Never taken: `manager` (
|
|
76
|
-
* pending) and `picture` (a file upload).
|
|
75
|
+
* Never taken: `manager` (a person, picked on the screen) and `picture` (a file upload).
|
|
77
76
|
*/
|
|
78
77
|
const DEPARTMENT_CREATE_FIELDS = DEPARTMENT_FIELDS.map(field => field.name);
|
|
79
78
|
function departmentEntryTarget() {
|
|
@@ -183,9 +182,8 @@ function departmentEntryTarget() {
|
|
|
183
182
|
* Kept to the fields a roster needs. Never taken: user, bankAccount, bankName, emergencyContact,
|
|
184
183
|
* emergencyContactPhone, contact, photo, supervisor. No update this round.
|
|
185
184
|
*
|
|
186
|
-
* The department is passed as an id the assistant resolved through the domain-scoped `departments` query
|
|
187
|
-
* createEmployee
|
|
188
|
-
* server's to fix, separately.
|
|
185
|
+
* The department is passed as an id the assistant resolved through the domain-scoped `departments` query, and
|
|
186
|
+
* createEmployee looks it up again inside the caller's domain.
|
|
189
187
|
*/
|
|
190
188
|
exports.EMPLOYEE_FORBIDDEN_FIELDS = ['user', 'bankAccount', 'bankName', 'emergencyContact', 'emergencyContactPhone', 'contact', 'photo', 'supervisor'];
|
|
191
189
|
const EMPLOYEE_FIELDS = [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"organization-entry-targets.js","sourceRoot":"","sources":["../../server/ai-entry/organization-entry-targets.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyEA,sDAiGC;AA4BD,kDAmBC;AAOD,4DAEC;AArND,yEAWmC;AAEtB,QAAA,uBAAuB,GAAG,yBAAyB,CAAA;AACnD,QAAA,qBAAqB,GAAG,uBAAuB,CAAA;AAE5D,4HAA4H;AAC5H,MAAM,mBAAmB,GACvB,kJAAkJ,CAAA;AAEpJ,MAAM,WAAW,GACf,4MAA4M,CAAA;AAE9M,4HAA4H;AAC5H,MAAM,mBAAmB,GAAG;IAC1B,KAAK,EAAE,mBAAmB;IAC1B,SAAS,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC;QAC5B,OAAO,EAAE;YACP,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE;YACjD,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE;SACvD;QACD,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE;KACpC,CAAC;IACF,SAAS,EAAE,CAAC,IAAS,EAAE,IAAY,EAAE,EAAE,CAAC,IAAA,2CAAgB,EAAC,IAAI,EAAE,WAAW,EAAE,KAAK,IAAI,EAAE,EAAE,IAAI,CAAC;CAC/F,CAAA;AAED,MAAM,iBAAiB,GAAiB;IACtC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,E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,IAAI,EAAE,EAAE,CAAC,CAAA;YAC/D,MAAM,CAAC,EAAE,aAAa,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,mDAAQ,uBAAuB,uDAAU,8BAA8B,uDAAU,SAAS,IAAE,CAAC,CAAA;YACjK,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,SAAS,EAAE,EAAE,CAAC,KAAK,CAAC,EAAS,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,WAAW,CAAQ,EAAE,CAAC,CAAA;YAC7J,OAAO,IAAA,yCAAc,EAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;QACvC,CAAC;KACF,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,SAAgB,wBAAwB;IACtC,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAAA;AAClC,CAAC","sourcesContent":["/*\n * AI 입력 targets of the organization - what an application may hand its assistant so that departments\n * (and, only by an explicit product decision, employees) are entered from material\n * (operato-application/design/ai/data-entry.md).\n *\n * Plain declarations: this package does not depend on @things-factory/ai-assistant. An application that runs\n * the assistant passes them to `registerEntryTarget` and names their keys in its modes. Every row is entered\n * through the organization's own mutation, run as the person - the same `@privilege` and checks as the screens.\n *\n * The checks read through the repository of the request's domain only, and import it when they run, so that\n * reading these declarations stays light.\n */\nimport type { EntryField, EntryRow, EntryTargetDeclaration } from './entry-target-shape'\nimport {\n changedParentId,\n codeAndName,\n departmentChangeIssues,\n departmentIssues,\n departmentsNamed,\n employeeIssues,\n inputOf,\n matching,\n parentVerdictOf,\n type ParentVerdict\n} from './organization-entry-rules'\n\nexport const ORGANIZATION_DEPARTMENT = 'organization.department'\nexport const ORGANIZATION_EMPLOYEE = 'organization.employee'\n\n/** Departments of the person's domain whose name or 관리번호 holds the text - `search` filters are OR'd by the list builder. */\nconst DEPARTMENTS_BY_TEXT =\n 'query ($filters: [Filter!], $pagination: Pagination) { departments(filters: $filters, pagination: $pagination) { items { id controlNo name } } }'\n\nconst DEPARTMENTS =\n 'query ($filters: [Filter!], $pagination: Pagination) { departments(filters: $filters, pagination: $pagination) { items { id controlNo name description active extension parent { id controlNo name } } } }'\n\n/** A department the model names in words, found as the person through `departments` - the id is what the mutation takes. */\nconst departmentReference = {\n query: DEPARTMENTS_BY_TEXT,\n variables: (said: string) => ({\n filters: [\n { name: 'name', operator: 'search', value: said },\n { name: 'controlNo', operator: 'search', value: said }\n ],\n pagination: { page: 1, limit: 200 }\n }),\n recordsOf: (data: any, said: string) => departmentsNamed(data?.departments?.items ?? [], said)\n}\n\nconst DEPARTMENT_FIELDS: EntryField[] = [\n { name: 'controlNo', type: 'string', required: true, labelKey: 'field.control-no', description: \"the department's code (관리번호) as the material writes it\" },\n { name: 'name', type: 'string', required: true, labelKey: 'field.name', description: 'the department name' },\n { name: 'description', type: 'string', labelKey: 'field.description' },\n { name: 'active', type: 'boolean', labelKey: 'field.active', description: 'false only when the material says the department is closed or not in use' },\n { name: 'extension', type: 'string', labelKey: 'field.extension', description: \"the department's phone extension (내선 번호)\" },\n {\n name: 'parent',\n type: 'reference',\n labelKey: 'field.parent-department',\n description: 'the department it belongs under, by its name or 관리번호. Leave it out for a top-level department.',\n reference: departmentReference\n }\n]\n\n/* DepartmentPatch has no `extension` - the update changes only what the patch can carry. */\nconst DEPARTMENT_UPDATE_FIELDS = ['controlNo', 'name', 'description', 'active', 'parent']\n\n/*\n * Never taken: `manager` (the mutation looks the employee up without the domain - a separate security fix is\n * pending) and `picture` (a file upload).\n */\nconst DEPARTMENT_CREATE_FIELDS = DEPARTMENT_FIELDS.map(field => field.name)\n\nexport function departmentEntryTarget(): EntryTargetDeclaration {\n return {\n key: ORGANIZATION_DEPARTMENT,\n labelKey: 'label.organization-entry-department',\n description:\n 'one department of the organization: its code (관리번호), its name, a description, its phone extension, whether it is active, and the department it belongs under.',\n mutation: 'mutation ($department: NewDepartment!) { createDepartment(department: $department) { id controlNo name } }',\n fields: DEPARTMENT_FIELDS,\n maxRows: 200,\n variables: (row: EntryRow) => ({ department: inputOf(row.values, DEPARTMENT_CREATE_FIELDS, ['parent']) }),\n appliedOf: (data, row) => ({ id: data?.createDepartment?.id, label: codeAndName(data?.createDepartment ?? row.values) }),\n\n check: async (rows, { state }) => {\n const domainId = state?.domain?.id\n const names = [...new Set(rows.map(row => row.values.name).filter((v): v is string => typeof v === 'string' && !!v.trim()).map(v => v.trim()))]\n const codes = [...new Set(rows.map(row => row.values.controlNo).filter((v): v is string => typeof v === 'string' && !!v.trim()).map(v => v.trim()))]\n if (!domainId || (!names.length && !codes.length)) return departmentIssues(rows, [])\n const [{ getRepository }, { Department }, { In }] = await Promise.all([import('@things-factory/shell'), import('../service/department/department'), import('typeorm')])\n const existing = await getRepository(Department).find({\n where: [\n ...(names.length ? [{ domain: { id: domainId }, name: In(names) }] : []),\n ...(codes.length ? [{ domain: { id: domainId }, controlNo: In(codes) }] : [])\n ] as any,\n select: ['id', 'name', 'controlNo'] as any\n })\n return departmentIssues(rows, existing)\n },\n\n update: {\n read: {\n query: DEPARTMENTS,\n variables: ids => ({ filters: [{ name: 'id', operator: 'in', value: ids }], pagination: { page: 1, limit: ids.length } }),\n recordsOf: data => data?.departments?.items ?? []\n },\n find: {\n query: DEPARTMENTS,\n variables: criteria => ({\n filters: ['name', 'controlNo'].filter(name => typeof criteria?.[name] === 'string' && criteria[name]).map(name => ({ name, operator: 'search', value: criteria[name] })),\n pagination: { page: 1, limit: 200 }\n }),\n recordsOf: (data, criteria) => matching(data?.departments?.items ?? [], criteria),\n criteria: [\n { name: 'name', type: 'string', description: 'a piece of the department name' },\n { name: 'controlNo', type: 'string', description: \"a piece of the department's 관리번호\" }\n ]\n },\n mutation: 'mutation ($id: String!, $patch: DepartmentPatch!) { updateDepartment(id: $id, patch: $patch) { id } }',\n variables: ({ id, values }) => ({ id, patch: inputOf(values, DEPARTMENT_UPDATE_FIELDS, ['parent']) }),\n labelOf: record => codeAndName(record),\n fields: DEPARTMENT_UPDATE_FIELDS,\n\n /*\n * A new name or 관리번호 another department has, and a parent the department's own rule refuses - asked through\n * `checkedParent` itself, which only reads: it walks up from the parent within the domain and throws.\n */\n check: async (rows, { state }) => {\n const domain = state?.domain\n if (!domain?.id) return departmentChangeIssues(rows, [])\n const given = (name: string) => [...new Set(rows.filter(row => name in row.values).map(row => row.values[name]).filter((v): v is string => typeof v === 'string' && !!v.trim()).map(v => v.trim()))]\n const [names, codes] = [given('name'), given('controlNo')]\n const [{ getRepository }, { Department }, { checkedParent }, { In }] = await Promise.all([\n import('@things-factory/shell'),\n import('../service/department/department'),\n import('../service/department/department-parent'),\n import('typeorm')\n ])\n const repository = getRepository(Department)\n const existing =\n names.length || codes.length\n ? await repository.find({\n where: [\n ...(names.length ? [{ domain: { id: domain.id }, name: In(names) }] : []),\n ...(codes.length ? [{ domain: { id: domain.id }, controlNo: In(codes) }] : [])\n ] as any,\n select: ['id', 'name', 'controlNo'] as any\n })\n : []\n const parents: ParentVerdict[] = []\n for (const row of rows) {\n const parentId = changedParentId(row.values)\n if (!parentId) {\n parents.push(undefined)\n continue\n }\n try {\n await checkedParent(row.id, { parent: { id: parentId } }, repository, domain)\n parents.push(undefined)\n } catch (error: any) {\n const verdict = parentVerdictOf(error)\n if (!verdict) throw error\n parents.push(verdict)\n }\n }\n return departmentChangeIssues(rows, existing as any, parents)\n }\n }\n }\n}\n\n/*\n * ── 직원 (employee) ──────────────────────────────────────────────────────────────────────────────────\n *\n * PERSONAL DATA. A row of this target is a person's name, position and hire day, and proposing it sends that\n * material to an external model. It is declared here so the shape is settled, and **no application opens it**:\n * a mode may name `organization.employee` only by an explicit product decision.\n *\n * Kept to the fields a roster needs. Never taken: user, bankAccount, bankName, emergencyContact,\n * emergencyContactPhone, contact, photo, supervisor. No update this round.\n *\n * The department is passed as an id the assistant resolved through the domain-scoped `departments` query.\n * createEmployee itself looks the department (and the supervisor) up by id without the domain - that is the\n * server's to fix, separately.\n */\nexport const EMPLOYEE_FORBIDDEN_FIELDS = ['user', 'bankAccount', 'bankName', 'emergencyContact', 'emergencyContactPhone', 'contact', 'photo', 'supervisor']\n\nconst EMPLOYEE_FIELDS: EntryField[] = [\n { name: 'controlNo', type: 'string', required: true, labelKey: 'field.control-no', description: 'the employee number (사번) as the material writes it' },\n { name: 'name', type: 'string', required: true, labelKey: 'field.name', description: \"the person's name\" },\n { name: 'jobPosition', type: 'string', labelKey: 'label.job-position', description: 'the rank (직급) - 사원, 대리, 과장...' },\n { name: 'jobResponsibility', type: 'string', labelKey: 'label.job-responsibility', description: 'the role (직책) - 팀장, 파트장...' },\n { name: 'type', type: 'enum', values: ['FULLTIME', 'PARTTIME', 'TEMPORARY'], labelKey: 'field.type', valueKeyPrefix: 'text.employee-type-' },\n { name: 'hiredOn', type: 'date', labelKey: 'field.hired-on', description: 'the day the person was hired' },\n { name: 'department', type: 'reference', labelKey: 'field.department', description: 'the department, by its name or 관리번호', reference: departmentReference }\n]\n\nexport function employeeEntryTarget(): EntryTargetDeclaration {\n return {\n key: ORGANIZATION_EMPLOYEE,\n labelKey: 'label.organization-entry-employee',\n description: 'one employee: the employee number (사번), the name, the rank and the role, the kind of employment, the day hired, and the department.',\n mutation: 'mutation ($employee: NewEmployee!) { createEmployee(employee: $employee) { id controlNo name } }',\n fields: EMPLOYEE_FIELDS,\n maxRows: 200,\n variables: (row: EntryRow) => ({ employee: inputOf(row.values, EMPLOYEE_FIELDS.map(field => field.name), ['department']) }),\n appliedOf: (data, row) => ({ id: data?.createEmployee?.id, label: codeAndName(data?.createEmployee ?? row.values) }),\n check: async (rows, { state }) => {\n const domainId = state?.domain?.id\n const codes = [...new Set(rows.map(row => row.values.controlNo).filter((v): v is string => typeof v === 'string' && !!v.trim()).map(v => v.trim()))]\n if (!domainId || !codes.length) return employeeIssues(rows, [])\n const [{ getRepository }, { Employee }, { In }] = await Promise.all([import('@things-factory/shell'), import('../service/employee/employee'), import('typeorm')])\n const existing = await getRepository(Employee).find({ where: { domain: { id: domainId }, controlNo: In(codes) } as any, select: ['id', 'controlNo'] as any })\n return employeeIssues(rows, existing)\n }\n }\n}\n\n/**\n * The organization's AI 입력 targets an application may register as a whole - the department. The employee is\n * left out on purpose: it is taken only by name, `employeeEntryTarget()`, after a product decision (see the note\n * above `EMPLOYEE_FORBIDDEN_FIELDS`), so registering this list never brings it along.\n */\nexport function organizationEntryTargets(): EntryTargetDeclaration[] {\n return [departmentEntryTarget()]\n}\n"]}
|
|
1
|
+
{"version":3,"file":"organization-entry-targets.js","sourceRoot":"","sources":["../../server/ai-entry/organization-entry-targets.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwEA,sDAiGC;AA2BD,kDAmBC;AAOD,4DAEC;AAnND,yEAWmC;AAEtB,QAAA,uBAAuB,GAAG,yBAAyB,CAAA;AACnD,QAAA,qBAAqB,GAAG,uBAAuB,CAAA;AAE5D,4HAA4H;AAC5H,MAAM,mBAAmB,GACvB,kJAAkJ,CAAA;AAEpJ,MAAM,WAAW,GACf,4MAA4M,CAAA;AAE9M,4HAA4H;AAC5H,MAAM,mBAAmB,GAAG;IAC1B,KAAK,EAAE,mBAAmB;IAC1B,SAAS,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC;QAC5B,OAAO,EAAE;YACP,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE;YACjD,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE;SACvD;QACD,UAAU,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE;KACpC,CAAC;IACF,SAAS,EAAE,CAAC,IAAS,EAAE,IAAY,EAAE,EAAE,CAAC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CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;YACpJ,IAAI,CAAC,QAAQ,IAAI,CAAC,KAAK,CAAC,MAAM;gBAAE,OAAO,IAAA,yCAAc,EAAC,IAAI,EAAE,EAAE,CAAC,CAAA;YAC/D,MAAM,CAAC,EAAE,aAAa,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,mDAAQ,uBAAuB,uDAAU,8BAA8B,uDAAU,SAAS,IAAE,CAAC,CAAA;YACjK,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,SAAS,EAAE,EAAE,CAAC,KAAK,CAAC,EAAS,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,WAAW,CAAQ,EAAE,CAAC,CAAA;YAC7J,OAAO,IAAA,yCAAc,EAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;QACvC,CAAC;KACF,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,SAAgB,wBAAwB;IACtC,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAAA;AAClC,CAAC","sourcesContent":["/*\n * AI 입력 targets of the organization - what an application may hand its assistant so that departments\n * (and, only by an explicit product decision, employees) are entered from material\n * (operato-application/design/ai/data-entry.md).\n *\n * Plain declarations: this package does not depend on @things-factory/ai-assistant. An application that runs\n * the assistant passes them to `registerEntryTarget` and names their keys in its modes. Every row is entered\n * through the organization's own mutation, run as the person - the same `@privilege` and checks as the screens.\n *\n * The checks read through the repository of the request's domain only, and import it when they run, so that\n * reading these declarations stays light.\n */\nimport type { EntryField, EntryRow, EntryTargetDeclaration } from './entry-target-shape'\nimport {\n changedParentId,\n codeAndName,\n departmentChangeIssues,\n departmentIssues,\n departmentsNamed,\n employeeIssues,\n inputOf,\n matching,\n parentVerdictOf,\n type ParentVerdict\n} from './organization-entry-rules'\n\nexport const ORGANIZATION_DEPARTMENT = 'organization.department'\nexport const ORGANIZATION_EMPLOYEE = 'organization.employee'\n\n/** Departments of the person's domain whose name or 관리번호 holds the text - `search` filters are OR'd by the list builder. */\nconst DEPARTMENTS_BY_TEXT =\n 'query ($filters: [Filter!], $pagination: Pagination) { departments(filters: $filters, pagination: $pagination) { items { id controlNo name } } }'\n\nconst DEPARTMENTS =\n 'query ($filters: [Filter!], $pagination: Pagination) { departments(filters: $filters, pagination: $pagination) { items { id controlNo name description active extension parent { id controlNo name } } } }'\n\n/** A department the model names in words, found as the person through `departments` - the id is what the mutation takes. */\nconst departmentReference = {\n query: DEPARTMENTS_BY_TEXT,\n variables: (said: string) => ({\n filters: [\n { name: 'name', operator: 'search', value: said },\n { name: 'controlNo', operator: 'search', value: said }\n ],\n pagination: { page: 1, limit: 200 }\n }),\n recordsOf: (data: any, said: string) => departmentsNamed(data?.departments?.items ?? [], said)\n}\n\nconst DEPARTMENT_FIELDS: EntryField[] = [\n { name: 'controlNo', type: 'string', required: true, labelKey: 'field.control-no', description: \"the department's code (관리번호) as the material writes it\" },\n { name: 'name', type: 'string', required: true, labelKey: 'field.name', description: 'the department name' },\n { name: 'description', type: 'string', labelKey: 'field.description' },\n { name: 'active', type: 'boolean', labelKey: 'field.active', description: 'false only when the material says the department is closed or not in use' },\n { name: 'extension', type: 'string', labelKey: 'field.extension', description: \"the department's phone extension (내선 번호)\" },\n {\n name: 'parent',\n type: 'reference',\n labelKey: 'field.parent-department',\n description: 'the department it belongs under, by its name or 관리번호. Leave it out for a top-level department.',\n reference: departmentReference\n }\n]\n\n/* DepartmentPatch has no `extension` - the update changes only what the patch can carry. */\nconst DEPARTMENT_UPDATE_FIELDS = ['controlNo', 'name', 'description', 'active', 'parent']\n\n/*\n * Never taken: `manager` (a person, picked on the screen) and `picture` (a file upload).\n */\nconst DEPARTMENT_CREATE_FIELDS = DEPARTMENT_FIELDS.map(field => field.name)\n\nexport function departmentEntryTarget(): EntryTargetDeclaration {\n return {\n key: ORGANIZATION_DEPARTMENT,\n labelKey: 'label.organization-entry-department',\n description:\n 'one department of the organization: its code (관리번호), its name, a description, its phone extension, whether it is active, and the department it belongs under.',\n mutation: 'mutation ($department: NewDepartment!) { createDepartment(department: $department) { id controlNo name } }',\n fields: DEPARTMENT_FIELDS,\n maxRows: 200,\n variables: (row: EntryRow) => ({ department: inputOf(row.values, DEPARTMENT_CREATE_FIELDS, ['parent']) }),\n appliedOf: (data, row) => ({ id: data?.createDepartment?.id, label: codeAndName(data?.createDepartment ?? row.values) }),\n\n check: async (rows, { state }) => {\n const domainId = state?.domain?.id\n const names = [...new Set(rows.map(row => row.values.name).filter((v): v is string => typeof v === 'string' && !!v.trim()).map(v => v.trim()))]\n const codes = [...new Set(rows.map(row => row.values.controlNo).filter((v): v is string => typeof v === 'string' && !!v.trim()).map(v => v.trim()))]\n if (!domainId || (!names.length && !codes.length)) return departmentIssues(rows, [])\n const [{ getRepository }, { Department }, { In }] = await Promise.all([import('@things-factory/shell'), import('../service/department/department'), import('typeorm')])\n const existing = await getRepository(Department).find({\n where: [\n ...(names.length ? [{ domain: { id: domainId }, name: In(names) }] : []),\n ...(codes.length ? [{ domain: { id: domainId }, controlNo: In(codes) }] : [])\n ] as any,\n select: ['id', 'name', 'controlNo'] as any\n })\n return departmentIssues(rows, existing)\n },\n\n update: {\n read: {\n query: DEPARTMENTS,\n variables: ids => ({ filters: [{ name: 'id', operator: 'in', value: ids }], pagination: { page: 1, limit: ids.length } }),\n recordsOf: data => data?.departments?.items ?? []\n },\n find: {\n query: DEPARTMENTS,\n variables: criteria => ({\n filters: ['name', 'controlNo'].filter(name => typeof criteria?.[name] === 'string' && criteria[name]).map(name => ({ name, operator: 'search', value: criteria[name] })),\n pagination: { page: 1, limit: 200 }\n }),\n recordsOf: (data, criteria) => matching(data?.departments?.items ?? [], criteria),\n criteria: [\n { name: 'name', type: 'string', description: 'a piece of the department name' },\n { name: 'controlNo', type: 'string', description: \"a piece of the department's 관리번호\" }\n ]\n },\n mutation: 'mutation ($id: String!, $patch: DepartmentPatch!) { updateDepartment(id: $id, patch: $patch) { id } }',\n variables: ({ id, values }) => ({ id, patch: inputOf(values, DEPARTMENT_UPDATE_FIELDS, ['parent']) }),\n labelOf: record => codeAndName(record),\n fields: DEPARTMENT_UPDATE_FIELDS,\n\n /*\n * A new name or 관리번호 another department has, and a parent the department's own rule refuses - asked through\n * `checkedParent` itself, which only reads: it walks up from the parent within the domain and throws.\n */\n check: async (rows, { state }) => {\n const domain = state?.domain\n if (!domain?.id) return departmentChangeIssues(rows, [])\n const given = (name: string) => [...new Set(rows.filter(row => name in row.values).map(row => row.values[name]).filter((v): v is string => typeof v === 'string' && !!v.trim()).map(v => v.trim()))]\n const [names, codes] = [given('name'), given('controlNo')]\n const [{ getRepository }, { Department }, { checkedParent }, { In }] = await Promise.all([\n import('@things-factory/shell'),\n import('../service/department/department'),\n import('../service/department/department-parent'),\n import('typeorm')\n ])\n const repository = getRepository(Department)\n const existing =\n names.length || codes.length\n ? await repository.find({\n where: [\n ...(names.length ? [{ domain: { id: domain.id }, name: In(names) }] : []),\n ...(codes.length ? [{ domain: { id: domain.id }, controlNo: In(codes) }] : [])\n ] as any,\n select: ['id', 'name', 'controlNo'] as any\n })\n : []\n const parents: ParentVerdict[] = []\n for (const row of rows) {\n const parentId = changedParentId(row.values)\n if (!parentId) {\n parents.push(undefined)\n continue\n }\n try {\n await checkedParent(row.id, { parent: { id: parentId } }, repository, domain)\n parents.push(undefined)\n } catch (error: any) {\n const verdict = parentVerdictOf(error)\n if (!verdict) throw error\n parents.push(verdict)\n }\n }\n return departmentChangeIssues(rows, existing as any, parents)\n }\n }\n }\n}\n\n/*\n * ── 직원 (employee) ──────────────────────────────────────────────────────────────────────────────────\n *\n * PERSONAL DATA. A row of this target is a person's name, position and hire day, and proposing it sends that\n * material to an external model. It is declared here so the shape is settled, and **no application opens it**:\n * a mode may name `organization.employee` only by an explicit product decision.\n *\n * Kept to the fields a roster needs. Never taken: user, bankAccount, bankName, emergencyContact,\n * emergencyContactPhone, contact, photo, supervisor. No update this round.\n *\n * The department is passed as an id the assistant resolved through the domain-scoped `departments` query, and\n * createEmployee looks it up again inside the caller's domain.\n */\nexport const EMPLOYEE_FORBIDDEN_FIELDS = ['user', 'bankAccount', 'bankName', 'emergencyContact', 'emergencyContactPhone', 'contact', 'photo', 'supervisor']\n\nconst EMPLOYEE_FIELDS: EntryField[] = [\n { name: 'controlNo', type: 'string', required: true, labelKey: 'field.control-no', description: 'the employee number (사번) as the material writes it' },\n { name: 'name', type: 'string', required: true, labelKey: 'field.name', description: \"the person's name\" },\n { name: 'jobPosition', type: 'string', labelKey: 'label.job-position', description: 'the rank (직급) - 사원, 대리, 과장...' },\n { name: 'jobResponsibility', type: 'string', labelKey: 'label.job-responsibility', description: 'the role (직책) - 팀장, 파트장...' },\n { name: 'type', type: 'enum', values: ['FULLTIME', 'PARTTIME', 'TEMPORARY'], labelKey: 'field.type', valueKeyPrefix: 'text.employee-type-' },\n { name: 'hiredOn', type: 'date', labelKey: 'field.hired-on', description: 'the day the person was hired' },\n { name: 'department', type: 'reference', labelKey: 'field.department', description: 'the department, by its name or 관리번호', reference: departmentReference }\n]\n\nexport function employeeEntryTarget(): EntryTargetDeclaration {\n return {\n key: ORGANIZATION_EMPLOYEE,\n labelKey: 'label.organization-entry-employee',\n description: 'one employee: the employee number (사번), the name, the rank and the role, the kind of employment, the day hired, and the department.',\n mutation: 'mutation ($employee: NewEmployee!) { createEmployee(employee: $employee) { id controlNo name } }',\n fields: EMPLOYEE_FIELDS,\n maxRows: 200,\n variables: (row: EntryRow) => ({ employee: inputOf(row.values, EMPLOYEE_FIELDS.map(field => field.name), ['department']) }),\n appliedOf: (data, row) => ({ id: data?.createEmployee?.id, label: codeAndName(data?.createEmployee ?? row.values) }),\n check: async (rows, { state }) => {\n const domainId = state?.domain?.id\n const codes = [...new Set(rows.map(row => row.values.controlNo).filter((v): v is string => typeof v === 'string' && !!v.trim()).map(v => v.trim()))]\n if (!domainId || !codes.length) return employeeIssues(rows, [])\n const [{ getRepository }, { Employee }, { In }] = await Promise.all([import('@things-factory/shell'), import('../service/employee/employee'), import('typeorm')])\n const existing = await getRepository(Employee).find({ where: { domain: { id: domainId }, controlNo: In(codes) } as any, select: ['id', 'controlNo'] as any })\n return employeeIssues(rows, existing)\n }\n }\n}\n\n/**\n * The organization's AI 입력 targets an application may register as a whole - the department. The employee is\n * left out on purpose: it is taken only by name, `employeeEntryTarget()`, after a product decision (see the note\n * above `EMPLOYEE_FORBIDDEN_FIELDS`), so registering this list never brings it along.\n */\nexport function organizationEntryTargets(): EntryTargetDeclaration[] {\n return [departmentEntryTarget()]\n}\n"]}
|
|
@@ -10,12 +10,11 @@ const department_1 = require("./department");
|
|
|
10
10
|
const department_type_1 = require("./department-type");
|
|
11
11
|
const employee_1 = require("../employee/employee");
|
|
12
12
|
const department_parent_1 = require("./department-parent");
|
|
13
|
+
const domain_reference_1 = require("../domain-reference");
|
|
13
14
|
let DepartmentMutation = class DepartmentMutation {
|
|
14
15
|
async createDepartment(department, context) {
|
|
15
16
|
const { domain, user, tx } = context.state;
|
|
16
|
-
const manager = 'manager' in department
|
|
17
|
-
? department.manager && (await (0, shell_1.getRepository)(employee_1.Employee, tx).findOneBy({ id: department.manager.id }))
|
|
18
|
-
: undefined;
|
|
17
|
+
const manager = await (0, domain_reference_1.referenceInDomain)((0, shell_1.getRepository)(employee_1.Employee, tx), 'manager' in department ? department.manager : undefined, domain, 'manager');
|
|
19
18
|
const parent = await (0, department_parent_1.checkedParent)(undefined, department, (0, shell_1.getRepository)(department_1.Department, tx), domain);
|
|
20
19
|
const result = await (0, shell_1.getRepository)(department_1.Department, tx).save({
|
|
21
20
|
...department,
|
|
@@ -42,9 +41,7 @@ let DepartmentMutation = class DepartmentMutation {
|
|
|
42
41
|
const department = await repository.findOne({
|
|
43
42
|
where: { domain: { id: domain.id }, id }
|
|
44
43
|
});
|
|
45
|
-
const manager = 'manager' in patch
|
|
46
|
-
? patch.manager && (await (0, shell_1.getRepository)(employee_1.Employee, tx).findOneBy({ id: patch.manager.id }))
|
|
47
|
-
: undefined;
|
|
44
|
+
const manager = await (0, domain_reference_1.referenceInDomain)((0, shell_1.getRepository)(employee_1.Employee, tx), 'manager' in patch ? patch.manager : undefined, domain, 'manager');
|
|
48
45
|
const parent = await (0, department_parent_1.checkedParent)(id, patch, repository, domain);
|
|
49
46
|
const result = await repository.save({
|
|
50
47
|
...department,
|
|
@@ -74,9 +71,7 @@ let DepartmentMutation = class DepartmentMutation {
|
|
|
74
71
|
if (_createRecords.length > 0) {
|
|
75
72
|
for (let i = 0; i < _createRecords.length; i++) {
|
|
76
73
|
const newRecord = _createRecords[i];
|
|
77
|
-
const manager = 'manager' in newRecord
|
|
78
|
-
? newRecord.manager && (await (0, shell_1.getRepository)(employee_1.Employee, tx).findOneBy({ id: newRecord.manager.id }))
|
|
79
|
-
: undefined;
|
|
74
|
+
const manager = await (0, domain_reference_1.referenceInDomain)((0, shell_1.getRepository)(employee_1.Employee, tx), 'manager' in newRecord ? newRecord.manager : undefined, domain, 'manager');
|
|
80
75
|
const parent = await (0, department_parent_1.checkedParent)(undefined, newRecord, departmentRepo, domain);
|
|
81
76
|
const result = await departmentRepo.save({
|
|
82
77
|
...newRecord,
|
|
@@ -107,9 +102,7 @@ let DepartmentMutation = class DepartmentMutation {
|
|
|
107
102
|
if (!department) {
|
|
108
103
|
throw new Error(`failed to find department to update: ${updateRecord.id}`);
|
|
109
104
|
}
|
|
110
|
-
const manager = 'manager' in updateRecord
|
|
111
|
-
? updateRecord.manager && (await (0, shell_1.getRepository)(employee_1.Employee, tx).findOneBy({ id: updateRecord.manager.id }))
|
|
112
|
-
: undefined;
|
|
105
|
+
const manager = await (0, domain_reference_1.referenceInDomain)((0, shell_1.getRepository)(employee_1.Employee, tx), 'manager' in updateRecord ? updateRecord.manager : undefined, domain, 'manager');
|
|
113
106
|
const parent = await (0, department_parent_1.checkedParent)(department.id, updateRecord, departmentRepo, domain);
|
|
114
107
|
const result = await departmentRepo.save({
|
|
115
108
|
...department,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"department-mutation.js","sourceRoot":"","sources":["../../../server/service/department/department-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA4B;AAE5B,iDAAqD;AACrD,qEAA0F;AAE1F,6CAAyC;AACzC,uDAAkE;AAClE,mDAA+C;AAC/C,2DAAmD;AAG5C,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAIvB,AAAN,KAAK,CAAC,gBAAgB,CACD,UAAyB,EACrC,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,MAAM,OAAO,GACX,SAAS,IAAI,UAAU;YACrB,CAAC,CAAC,UAAU,CAAC,OAAO,IAAI,CAAC,MAAM,IAAA,qBAAa,EAAC,mBAAQ,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,CAAC;YACpG,CAAC,CAAC,SAAS,CAAA;QAEf,MAAM,MAAM,GAAG,MAAM,IAAA,iCAAa,EAAC,SAAS,EAAE,UAAU,EAAE,IAAA,qBAAa,EAAC,uBAAU,EAAE,EAAE,CAAC,EAAE,MAAM,CAAC,CAAA;QAEhG,MAAM,MAAM,GAAG,MAAM,IAAA,qBAAa,EAAC,uBAAU,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC;YACtD,GAAG,UAAU;YACb,MAAM;YACN,MAAM;YACN,OAAO;YACP,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,IAAI;SACd,CAAC,CAAA;QAEF,IAAI,UAAU,CAAC,OA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OAAO,EAAE,EAAE,WAAW,EAAE,sBAAsB,EAAE,CAAC;IAC9C,mBAAA,IAAA,kBAAG,EAAC,IAAI,CAAC,CAAA;IAAc,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;0DAOnD;AAKK;IAHL,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,wBAAS,EAAC,qFAAqF,CAAC;IAChG,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,gCAAgC,EAAE,CAAC;IAE7E,mBAAA,IAAA,kBAAG,EAAC,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;IAC5B,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;2DAYP;AAKK;IAHL,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,wBAAS,EAAC,qFAAqF,CAAC;IAChG,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,gCAAgC,EAAE,CAAC;IAE7E,mBAAA,IAAA,kBAAG,EAAC,aAAa,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,iCAAe,CAAC,CAAC,CAAA;IAC7C,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;2DAYP;6BA7OU,kBAAkB;IAD9B,IAAA,uBAAQ,EAAC,uBAAU,CAAC;GACR,kBAAkB,CA8O9B","sourcesContent":["import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { getRepository } from '@things-factory/shell'\nimport { createAttachment, deleteAttachmentsByRef } from '@things-factory/attachment-base'\n\nimport { Department } from './department'\nimport { NewDepartment, DepartmentPatch } from './department-type'\nimport { Employee } from '../employee/employee'\nimport { checkedParent } from './department-parent'\n\n@Resolver(Department)\nexport class DepartmentMutation {\n @Directive('@transaction')\n @Directive('@privilege(category: \"department\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Department, { description: 'To create new Department' })\n async createDepartment(\n @Arg('department') department: NewDepartment,\n @Ctx() context: ResolverContext\n ): Promise<Department> {\n const { domain, user, tx } = context.state\n\n const manager =\n 'manager' in department\n ? department.manager && (await getRepository(Employee, tx).findOneBy({ id: department.manager.id }))\n : undefined\n\n const parent = await checkedParent(undefined, department, getRepository(Department, tx), domain)\n\n const result = await getRepository(Department, tx).save({\n ...department,\n parent,\n domain,\n manager,\n creator: user,\n updater: user\n })\n\n if (department.picture) {\n await createAttachment(\n null,\n {\n attachment: {\n file: department.picture,\n refType: Department.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n return result\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"department\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Department, { description: 'To modify Department information' })\n async updateDepartment(\n @Arg('id') id: string,\n @Arg('patch') patch: DepartmentPatch,\n @Ctx() context: ResolverContext\n ): Promise<Department> {\n const { domain, user, tx } = context.state\n\n const repository = getRepository(Department, tx)\n const department = await repository.findOne({\n where: { domain: { id: domain.id }, id }\n })\n\n const manager =\n 'manager' in patch\n ? patch.manager && (await getRepository(Employee, tx).findOneBy({ id: patch.manager.id }))\n : undefined\n\n const parent = await checkedParent(id, patch, repository, domain)\n\n const result = await repository.save({\n ...department,\n ...patch,\n ...(parent !== undefined && { parent }),\n manager,\n updater: user\n })\n\n if (patch.picture) {\n await deleteAttachmentsByRef(null, { refBys: [result.id] }, context)\n await createAttachment(\n null,\n {\n attachment: {\n file: patch.picture,\n refType: Department.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n return result\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"department\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => [Department], { description: \"To modify multiple Departments' information\" })\n async updateMultipleDepartment(\n @Arg('patches', type => [DepartmentPatch]) patches: DepartmentPatch[],\n @Ctx() context: ResolverContext\n ): Promise<Department[]> {\n const { domain, user, tx } = context.state\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 const departmentRepo = getRepository(Department, tx)\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const newRecord = _createRecords[i]\n const manager =\n 'manager' in newRecord\n ? newRecord.manager && (await getRepository(Employee, tx).findOneBy({ id: newRecord.manager.id }))\n : undefined\n\n const parent = await checkedParent(undefined, newRecord, departmentRepo, domain)\n\n const result = await departmentRepo.save({\n ...newRecord,\n parent,\n manager,\n domain,\n creator: user,\n updater: user\n })\n\n if (newRecord.picture) {\n await createAttachment(\n null,\n {\n attachment: {\n file: newRecord.picture,\n refType: Department.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const updateRecord = _updateRecords[i]\n const department = await departmentRepo.findOne({\n where: { domain: { id: domain.id }, id: updateRecord.id }\n })\n\n if (!department) {\n throw new Error(`failed to find department to update: ${updateRecord.id}`)\n }\n const manager =\n 'manager' in updateRecord\n ? updateRecord.manager && (await getRepository(Employee, tx).findOneBy({ id: updateRecord.manager.id }))\n : undefined\n\n const parent = await checkedParent(department.id, updateRecord, departmentRepo, domain)\n\n const result = await departmentRepo.save({\n ...department,\n ...updateRecord,\n ...(parent !== undefined && { parent }),\n manager,\n updater: user\n })\n\n if (updateRecord.picture) {\n await deleteAttachmentsByRef(null, { refBys: [result.id] }, context)\n await createAttachment(\n null,\n {\n attachment: {\n file: updateRecord.picture,\n refType: Department.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"department\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Boolean, { description: 'To delete Department' })\n async deleteDepartment(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await getRepository(Department, tx).softDelete({ domain: { id: domain.id }, id })\n // await deleteAttachmentsByRef(null, { refBys: [id] }, context)\n\n return true\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"department\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Boolean, { description: 'To delete multiple Departments' })\n async deleteDepartments(\n @Arg('ids', type => [String]) ids: string[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n await getRepository(Department, tx).softDelete({\n domain: { id: domain.id },\n id: In(ids)\n })\n\n // await deleteAttachmentsByRef(null, { refBys: ids }, context)\n\n return true\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"department\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Boolean, { description: 'To import multiple Departments' })\n async importDepartments(\n @Arg('departments', type => [DepartmentPatch]) departments: DepartmentPatch[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n const repository = getRepository(Department, tx)\n\n for (const department of departments) {\n const parent = await checkedParent(undefined, department, repository, domain)\n await repository.save({ domain, ...department, parent })\n }\n\n return true\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"department-mutation.js","sourceRoot":"","sources":["../../../server/service/department/department-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA4B;AAE5B,iDAAqD;AACrD,qEAA0F;AAE1F,6CAAyC;AACzC,uDAAkE;AAClE,mDAA+C;AAC/C,2DAAmD;AACnD,0DAAuD;AAGhD,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAIvB,AAAN,KAAK,CAAC,gBAAgB,CACD,UAAyB,EACrC,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,MAAM,OAAO,GAAG,MAAM,IAAA,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,CAAA;;;;2DAYP;6BArPU,kBAAkB;IAD9B,IAAA,uBAAQ,EAAC,uBAAU,CAAC;GACR,kBAAkB,CAsP9B","sourcesContent":["import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { getRepository } from '@things-factory/shell'\nimport { createAttachment, deleteAttachmentsByRef } from '@things-factory/attachment-base'\n\nimport { Department } from './department'\nimport { NewDepartment, DepartmentPatch } from './department-type'\nimport { Employee } from '../employee/employee'\nimport { checkedParent } from './department-parent'\nimport { referenceInDomain } from '../domain-reference'\n\n@Resolver(Department)\nexport class DepartmentMutation {\n @Directive('@transaction')\n @Directive('@privilege(category: \"department\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Department, { description: 'To create new Department' })\n async createDepartment(\n @Arg('department') department: NewDepartment,\n @Ctx() context: ResolverContext\n ): Promise<Department> {\n const { domain, user, tx } = context.state\n\n const manager = await referenceInDomain(\n getRepository(Employee, tx),\n 'manager' in department ? department.manager : undefined,\n domain,\n 'manager'\n )\n\n const parent = await checkedParent(undefined, department, getRepository(Department, tx), domain)\n\n const result = await getRepository(Department, tx).save({\n ...department,\n parent,\n domain,\n manager,\n creator: user,\n updater: user\n })\n\n if (department.picture) {\n await createAttachment(\n null,\n {\n attachment: {\n file: department.picture,\n refType: Department.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n return result\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"department\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Department, { description: 'To modify Department information' })\n async updateDepartment(\n @Arg('id') id: string,\n @Arg('patch') patch: DepartmentPatch,\n @Ctx() context: ResolverContext\n ): Promise<Department> {\n const { domain, user, tx } = context.state\n\n const repository = getRepository(Department, tx)\n const department = await repository.findOne({\n where: { domain: { id: domain.id }, id }\n })\n\n const manager = await referenceInDomain(\n getRepository(Employee, tx),\n 'manager' in patch ? patch.manager : undefined,\n domain,\n 'manager'\n )\n\n const parent = await checkedParent(id, patch, repository, domain)\n\n const result = await repository.save({\n ...department,\n ...patch,\n ...(parent !== undefined && { parent }),\n manager,\n updater: user\n })\n\n if (patch.picture) {\n await deleteAttachmentsByRef(null, { refBys: [result.id] }, context)\n await createAttachment(\n null,\n {\n attachment: {\n file: patch.picture,\n refType: Department.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n return result\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"department\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => [Department], { description: \"To modify multiple Departments' information\" })\n async updateMultipleDepartment(\n @Arg('patches', type => [DepartmentPatch]) patches: DepartmentPatch[],\n @Ctx() context: ResolverContext\n ): Promise<Department[]> {\n const { domain, user, tx } = context.state\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 const departmentRepo = getRepository(Department, tx)\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const newRecord = _createRecords[i]\n const manager = await referenceInDomain(\n getRepository(Employee, tx),\n 'manager' in newRecord ? newRecord.manager : undefined,\n domain,\n 'manager'\n )\n\n const parent = await checkedParent(undefined, newRecord, departmentRepo, domain)\n\n const result = await departmentRepo.save({\n ...newRecord,\n parent,\n manager,\n domain,\n creator: user,\n updater: user\n })\n\n if (newRecord.picture) {\n await createAttachment(\n null,\n {\n attachment: {\n file: newRecord.picture,\n refType: Department.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const updateRecord = _updateRecords[i]\n const department = await departmentRepo.findOne({\n where: { domain: { id: domain.id }, id: updateRecord.id }\n })\n\n if (!department) {\n throw new Error(`failed to find department to update: ${updateRecord.id}`)\n }\n const manager = await referenceInDomain(\n getRepository(Employee, tx),\n 'manager' in updateRecord ? updateRecord.manager : undefined,\n domain,\n 'manager'\n )\n\n const parent = await checkedParent(department.id, updateRecord, departmentRepo, domain)\n\n const result = await departmentRepo.save({\n ...department,\n ...updateRecord,\n ...(parent !== undefined && { parent }),\n manager,\n updater: user\n })\n\n if (updateRecord.picture) {\n await deleteAttachmentsByRef(null, { refBys: [result.id] }, context)\n await createAttachment(\n null,\n {\n attachment: {\n file: updateRecord.picture,\n refType: Department.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"department\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Boolean, { description: 'To delete Department' })\n async deleteDepartment(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await getRepository(Department, tx).softDelete({ domain: { id: domain.id }, id })\n // await deleteAttachmentsByRef(null, { refBys: [id] }, context)\n\n return true\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"department\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Boolean, { description: 'To delete multiple Departments' })\n async deleteDepartments(\n @Arg('ids', type => [String]) ids: string[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n await getRepository(Department, tx).softDelete({\n domain: { id: domain.id },\n id: In(ids)\n })\n\n // await deleteAttachmentsByRef(null, { refBys: ids }, context)\n\n return true\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"department\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Boolean, { description: 'To import multiple Departments' })\n async importDepartments(\n @Arg('departments', type => [DepartmentPatch]) departments: DepartmentPatch[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n const repository = getRepository(Department, tx)\n\n for (const department of departments) {\n const parent = await checkedParent(undefined, department, repository, domain)\n await repository.save({ domain, ...department, parent })\n }\n\n return true\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EntityManager, ObjectLiteral, Repository } from 'typeorm';
|
|
2
|
+
import { Domain } from '@things-factory/shell';
|
|
3
|
+
import { User } from '@things-factory/auth-base';
|
|
4
|
+
export declare function referenceInDomain<T extends ObjectLiteral>(repository: Repository<T>, ref: {
|
|
5
|
+
id?: string;
|
|
6
|
+
} | null | undefined, domain: Domain, what: string): Promise<T | null | undefined>;
|
|
7
|
+
export declare function userInDomain(ref: {
|
|
8
|
+
id?: string;
|
|
9
|
+
} | null | undefined, domain: Domain, tx?: EntityManager): Promise<User | null | undefined>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.referenceInDomain = referenceInDomain;
|
|
4
|
+
exports.userInDomain = userInDomain;
|
|
5
|
+
const shell_1 = require("@things-factory/shell");
|
|
6
|
+
const auth_base_1 = require("@things-factory/auth-base");
|
|
7
|
+
/*
|
|
8
|
+
* A record a patch points at, looked up inside the caller's domain.
|
|
9
|
+
*
|
|
10
|
+
* The lookups this replaces asked by id alone, so a mutation run in one domain could make its
|
|
11
|
+
* department's manager, or its employee's supervisor, a row of another domain: the id was all it
|
|
12
|
+
* took. The answer here is the same three as `checkedParent`:
|
|
13
|
+
*
|
|
14
|
+
* key absent, or undefined undefined — leave the reference as it is
|
|
15
|
+
* null, or no id null — clear it
|
|
16
|
+
* an id the row — refused when the domain has no such row
|
|
17
|
+
*/
|
|
18
|
+
async function referenceInDomain(repository, ref, domain, what) {
|
|
19
|
+
if (ref === undefined)
|
|
20
|
+
return undefined;
|
|
21
|
+
if (ref === null || !ref.id)
|
|
22
|
+
return null;
|
|
23
|
+
const found = await repository.findOne({ where: { domain: { id: domain.id }, id: ref.id } });
|
|
24
|
+
if (!found) {
|
|
25
|
+
throw new Error(`${what} not found in this domain: ${ref.id}`);
|
|
26
|
+
}
|
|
27
|
+
return found;
|
|
28
|
+
}
|
|
29
|
+
/*
|
|
30
|
+
* A user is not owned by a domain the way an employee is — it belongs to several, through
|
|
31
|
+
* `users_domains`. The one an employee is connected to has to be among this domain's users.
|
|
32
|
+
*/
|
|
33
|
+
async function userInDomain(ref, domain, tx) {
|
|
34
|
+
if (ref === undefined)
|
|
35
|
+
return undefined;
|
|
36
|
+
if (ref === null || !ref.id)
|
|
37
|
+
return null;
|
|
38
|
+
const found = await (0, shell_1.getRepository)(auth_base_1.User, tx)
|
|
39
|
+
.createQueryBuilder('user')
|
|
40
|
+
.innerJoin('user.domains', 'domain', 'domain.id = :domainId', { domainId: domain.id })
|
|
41
|
+
.where('user.id = :id', { id: ref.id })
|
|
42
|
+
.getOne();
|
|
43
|
+
if (!found) {
|
|
44
|
+
throw new Error(`user not found in this domain: ${ref.id}`);
|
|
45
|
+
}
|
|
46
|
+
return found;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=domain-reference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain-reference.js","sourceRoot":"","sources":["../../server/service/domain-reference.ts"],"names":[],"mappings":";;AAgBA,8CAeC;AAMD,oCAmBC;AAtDD,iDAA6D;AAC7D,yDAAgD;AAEhD;;;;;;;;;;GAUG;AACI,KAAK,UAAU,iBAAiB,CACrC,UAAyB,EACzB,GAAuC,EACvC,MAAc,EACd,IAAY;IAEZ,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,SAAS,CAAA;IACvC,IAAI,GAAG,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE;QAAE,OAAO,IAAI,CAAA;IAExC,MAAM,KAAK,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAS,EAAE,CAAC,CAAA;IACnG,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,8BAA8B,GAAG,CAAC,EAAE,EAAE,CAAC,CAAA;IAChE,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;;GAGG;AACI,KAAK,UAAU,YAAY,CAChC,GAAuC,EACvC,MAAc,EACd,EAAkB;IAElB,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,SAAS,CAAA;IACvC,IAAI,GAAG,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE;QAAE,OAAO,IAAI,CAAA;IAExC,MAAM,KAAK,GAAG,MAAM,IAAA,qBAAa,EAAC,gBAAI,EAAE,EAAE,CAAC;SACxC,kBAAkB,CAAC,MAAM,CAAC;SAC1B,SAAS,CAAC,cAAc,EAAE,QAAQ,EAAE,uBAAuB,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC;SACrF,KAAK,CAAC,eAAe,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC;SACtC,MAAM,EAAE,CAAA;IAEX,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,kCAAkC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAA;IAC7D,CAAC;IAED,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import { EntityManager, ObjectLiteral, Repository } from 'typeorm'\n\nimport { Domain, getRepository } from '@things-factory/shell'\nimport { User } from '@things-factory/auth-base'\n\n/*\n * A record a patch points at, looked up inside the caller's domain.\n *\n * The lookups this replaces asked by id alone, so a mutation run in one domain could make its\n * department's manager, or its employee's supervisor, a row of another domain: the id was all it\n * took. The answer here is the same three as `checkedParent`:\n *\n * key absent, or undefined undefined — leave the reference as it is\n * null, or no id null — clear it\n * an id the row — refused when the domain has no such row\n */\nexport async function referenceInDomain<T extends ObjectLiteral>(\n repository: Repository<T>,\n ref: { id?: string } | null | undefined,\n domain: Domain,\n what: string\n): Promise<T | null | undefined> {\n if (ref === undefined) return undefined\n if (ref === null || !ref.id) return null\n\n const found = await repository.findOne({ where: { domain: { id: domain.id }, id: ref.id } as any })\n if (!found) {\n throw new Error(`${what} not found in this domain: ${ref.id}`)\n }\n\n return found\n}\n\n/*\n * A user is not owned by a domain the way an employee is — it belongs to several, through\n * `users_domains`. The one an employee is connected to has to be among this domain's users.\n */\nexport async function userInDomain(\n ref: { id?: string } | null | undefined,\n domain: Domain,\n tx?: EntityManager\n): Promise<User | null | undefined> {\n if (ref === undefined) return undefined\n if (ref === null || !ref.id) return null\n\n const found = await getRepository(User, tx)\n .createQueryBuilder('user')\n .innerJoin('user.domains', 'domain', 'domain.id = :domainId', { domainId: domain.id })\n .where('user.id = :id', { id: ref.id })\n .getOne()\n\n if (!found) {\n throw new Error(`user not found in this domain: ${ref.id}`)\n }\n\n return found\n}\n"]}
|
|
@@ -5,26 +5,20 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const type_graphql_1 = require("type-graphql");
|
|
6
6
|
const typeorm_1 = require("typeorm");
|
|
7
7
|
const shell_1 = require("@things-factory/shell");
|
|
8
|
-
const auth_base_1 = require("@things-factory/auth-base");
|
|
9
8
|
const attachment_base_1 = require("@things-factory/attachment-base");
|
|
10
9
|
const contact_1 = require("@things-factory/contact");
|
|
11
10
|
const employee_1 = require("./employee");
|
|
12
11
|
const employee_type_1 = require("./employee-type");
|
|
13
12
|
const department_1 = require("../department/department");
|
|
14
13
|
const employee_day_1 = require("./employee-day");
|
|
14
|
+
const domain_reference_1 = require("../domain-reference");
|
|
15
15
|
const register_employee_as_system_user_1 = require("../../controllers/register-employee-as-system-user");
|
|
16
16
|
let EmployeeMutation = class EmployeeMutation {
|
|
17
17
|
async createEmployee(employee, context) {
|
|
18
18
|
const { domain, user, tx } = context.state;
|
|
19
|
-
const supervisor = 'supervisor' in employee
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const department = 'department' in employee
|
|
23
|
-
? employee.department && (await (0, shell_1.getRepository)(department_1.Department, tx).findOneBy({ id: employee.department.id }))
|
|
24
|
-
: undefined;
|
|
25
|
-
const connectedUser = 'user' in employee
|
|
26
|
-
? employee.user && (await (0, shell_1.getRepository)(auth_base_1.User, tx).findOneBy({ id: employee.user.id }))
|
|
27
|
-
: undefined;
|
|
19
|
+
const supervisor = await (0, domain_reference_1.referenceInDomain)((0, shell_1.getRepository)(employee_1.Employee, tx), 'supervisor' in employee ? employee.supervisor : undefined, domain, 'supervisor');
|
|
20
|
+
const department = await (0, domain_reference_1.referenceInDomain)((0, shell_1.getRepository)(department_1.Department, tx), 'department' in employee ? employee.department : undefined, domain, 'department');
|
|
21
|
+
const connectedUser = await (0, domain_reference_1.userInDomain)('user' in employee ? employee.user : undefined, domain, tx);
|
|
28
22
|
const result = await (0, shell_1.getRepository)(employee_1.Employee, tx).save({
|
|
29
23
|
...(0, employee_day_1.withDays)(employee),
|
|
30
24
|
supervisor,
|
|
@@ -47,13 +41,9 @@ let EmployeeMutation = class EmployeeMutation {
|
|
|
47
41
|
}
|
|
48
42
|
async updateEmployee(id, patch, context) {
|
|
49
43
|
const { domain, user, tx } = context.state;
|
|
50
|
-
const supervisor = 'supervisor' in patch
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const department = 'department' in patch
|
|
54
|
-
? patch.department && (await (0, shell_1.getRepository)(department_1.Department, tx).findOneBy({ id: patch.department.id }))
|
|
55
|
-
: undefined;
|
|
56
|
-
const connectedUser = 'user' in patch ? patch.user && (await (0, shell_1.getRepository)(auth_base_1.User, tx).findOneBy({ id: patch.user.id })) : undefined;
|
|
44
|
+
const supervisor = await (0, domain_reference_1.referenceInDomain)((0, shell_1.getRepository)(employee_1.Employee, tx), 'supervisor' in patch ? patch.supervisor : undefined, domain, 'supervisor');
|
|
45
|
+
const department = await (0, domain_reference_1.referenceInDomain)((0, shell_1.getRepository)(department_1.Department, tx), 'department' in patch ? patch.department : undefined, domain, 'department');
|
|
46
|
+
const connectedUser = await (0, domain_reference_1.userInDomain)('user' in patch ? patch.user : undefined, domain, tx);
|
|
57
47
|
const repository = (0, shell_1.getRepository)(employee_1.Employee, tx);
|
|
58
48
|
const employee = await repository.findOne({
|
|
59
49
|
where: { domain: { id: domain.id }, id }
|
|
@@ -88,15 +78,9 @@ let EmployeeMutation = class EmployeeMutation {
|
|
|
88
78
|
if (_createRecords.length > 0) {
|
|
89
79
|
for (let i = 0; i < _createRecords.length; i++) {
|
|
90
80
|
const newRecord = _createRecords[i];
|
|
91
|
-
const supervisor = 'supervisor' in newRecord
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const department = 'department' in newRecord
|
|
95
|
-
? newRecord.department && (await (0, shell_1.getRepository)(department_1.Department, tx).findOneBy({ id: newRecord.department.id }))
|
|
96
|
-
: undefined;
|
|
97
|
-
const connectedUser = 'user' in newRecord
|
|
98
|
-
? newRecord.user && (await (0, shell_1.getRepository)(auth_base_1.User, tx).findOneBy({ id: newRecord.user.id }))
|
|
99
|
-
: undefined;
|
|
81
|
+
const supervisor = await (0, domain_reference_1.referenceInDomain)((0, shell_1.getRepository)(employee_1.Employee, tx), 'supervisor' in newRecord ? newRecord.supervisor : undefined, domain, 'supervisor');
|
|
82
|
+
const department = await (0, domain_reference_1.referenceInDomain)((0, shell_1.getRepository)(department_1.Department, tx), 'department' in newRecord ? newRecord.department : undefined, domain, 'department');
|
|
83
|
+
const connectedUser = await (0, domain_reference_1.userInDomain)('user' in newRecord ? newRecord.user : undefined, domain, tx);
|
|
100
84
|
const result = await employeeRepo.save({
|
|
101
85
|
...(0, employee_day_1.withDays)(newRecord),
|
|
102
86
|
supervisor,
|
|
@@ -121,17 +105,9 @@ let EmployeeMutation = class EmployeeMutation {
|
|
|
121
105
|
if (_updateRecords.length > 0) {
|
|
122
106
|
for (let i = 0; i < _updateRecords.length; i++) {
|
|
123
107
|
const updateRecord = _updateRecords[i];
|
|
124
|
-
const supervisor = 'supervisor' in updateRecord
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
: undefined;
|
|
128
|
-
const department = 'department' in updateRecord
|
|
129
|
-
? updateRecord.department &&
|
|
130
|
-
(await (0, shell_1.getRepository)(department_1.Department, tx).findOneBy({ id: updateRecord.department.id }))
|
|
131
|
-
: undefined;
|
|
132
|
-
const connectedUser = 'user' in updateRecord
|
|
133
|
-
? updateRecord.user && (await (0, shell_1.getRepository)(auth_base_1.User, tx).findOneBy({ id: updateRecord.user.id }))
|
|
134
|
-
: undefined;
|
|
108
|
+
const supervisor = await (0, domain_reference_1.referenceInDomain)((0, shell_1.getRepository)(employee_1.Employee, tx), 'supervisor' in updateRecord ? updateRecord.supervisor : undefined, domain, 'supervisor');
|
|
109
|
+
const department = await (0, domain_reference_1.referenceInDomain)((0, shell_1.getRepository)(department_1.Department, tx), 'department' in updateRecord ? updateRecord.department : undefined, domain, 'department');
|
|
110
|
+
const connectedUser = await (0, domain_reference_1.userInDomain)('user' in updateRecord ? updateRecord.user : undefined, domain, tx);
|
|
135
111
|
const employee = await employeeRepo.findOne({
|
|
136
112
|
where: { domain: { id: domain.id }, id: updateRecord.id }
|
|
137
113
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"employee-mutation.js","sourceRoot":"","sources":["../../../server/service/employee/employee-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA4B;AAE5B,iDAAqD;AACrD,yDAAgD;AAChD,qEAA0F;AAC1F,qDAAiD;AAEjD,yCAAqC;AACrC,mDAA4D;AAC5D,yDAAqD;AACrD,iDAAyC;AAEzC,yGAI2D;AAGpD,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAOrB,AAAN,KAAK,CAAC,cAAc,CAAkB,QAAqB,EAAS,OAAwB;QAC1F,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,MAAM,UAAU,GACd,YAAY,IAAI,QAAQ;YACtB,CAAC,CAAC,QAAQ,CAAC,UAAU,IAAI,CAAC,MAAM,IAA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,CAAA;;;;oEAGP;2BAnXU,gBAAgB;IAD5B,IAAA,uBAAQ,EAAC,mBAAQ,CAAC;GACN,gBAAgB,CAoX5B","sourcesContent":["import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { getRepository } from '@things-factory/shell'\nimport { User } from '@things-factory/auth-base'\nimport { createAttachment, deleteAttachmentsByRef } from '@things-factory/attachment-base'\nimport { Contact } from '@things-factory/contact'\n\nimport { Employee } from './employee'\nimport { NewEmployee, EmployeePatch } from './employee-type'\nimport { Department } from '../department/department'\nimport { withDays } from './employee-day'\n\nimport {\n onDeleteEmployeeAsSystemUser,\n onUpdateEmployeeAsSystemUser,\n registerEmployeeAsSystemUser\n} from '../../controllers/register-employee-as-system-user'\n\n@Resolver(Employee)\nexport class EmployeeMutation {\n @Directive('@transaction')\n @Directive('@privilege(category: \"employee\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Employee, {\n description:\n 'Creates a new employee record with the provided details. Optionally associates the employee with a supervisor, department, and system user. If a photo is provided, it will be attached to the employee record.'\n })\n async createEmployee(@Arg('employee') employee: NewEmployee, @Ctx() context: ResolverContext): Promise<Employee> {\n const { domain, user, tx } = context.state\n\n const supervisor =\n 'supervisor' in employee\n ? employee.supervisor && (await getRepository(Employee, tx).findOneBy({ id: employee.supervisor.id }))\n : undefined\n\n const department =\n 'department' in employee\n ? employee.department && (await getRepository(Department, tx).findOneBy({ id: employee.department.id }))\n : undefined\n\n const connectedUser =\n 'user' in employee\n ? employee.user && (await getRepository(User, tx).findOneBy({ id: employee.user.id }))\n : undefined\n\n const result = await getRepository(Employee, tx).save({\n ...withDays(employee),\n supervisor,\n department,\n user: connectedUser,\n domain,\n creator: user,\n updater: user\n })\n\n if (employee.photo) {\n await createAttachment(\n null,\n {\n attachment: {\n file: employee.photo,\n refType: Employee.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n return result\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"employee\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Employee, {\n description:\n 'Updates the details of an existing employee identified by the given ID. Optionally updates the supervisor, department, system user, and photo associated with the employee.'\n })\n async updateEmployee(\n @Arg('id') id: string,\n @Arg('patch') patch: EmployeePatch,\n @Ctx() context: ResolverContext\n ): Promise<Employee> {\n const { domain, user, tx } = context.state\n\n const supervisor =\n 'supervisor' in patch\n ? patch.supervisor && (await getRepository(Employee, tx).findOneBy({ id: patch.supervisor.id }))\n : undefined\n\n const department =\n 'department' in patch\n ? patch.department && (await getRepository(Department, tx).findOneBy({ id: patch.department.id }))\n : undefined\n\n const connectedUser =\n 'user' in patch ? patch.user && (await getRepository(User, tx).findOneBy({ id: patch.user.id })) : undefined\n\n const repository = getRepository(Employee, tx)\n const employee = await repository.findOne({\n where: { domain: { id: domain.id }, id }\n })\n\n await onUpdateEmployeeAsSystemUser(patch, context)\n\n const result = await repository.save({\n ...employee,\n ...withDays(patch),\n supervisor,\n department,\n user: connectedUser,\n updater: user\n })\n\n if (patch.photo) {\n await deleteAttachmentsByRef(null, { refBys: [result.id] }, context)\n await createAttachment(\n null,\n {\n attachment: {\n file: patch.photo,\n refType: Employee.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n return result\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"employee\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => [Employee], {\n description:\n 'Updates or creates multiple employee records based on the provided patches. New employees are created if the \"cuFlag\" is \"+\", and existing employees are updated if the \"cuFlag\" is \"M\".'\n })\n async updateMultipleEmployee(\n @Arg('patches', type => [EmployeePatch]) patches: EmployeePatch[],\n @Ctx() context: ResolverContext\n ): Promise<Employee[]> {\n const { domain, user, tx } = context.state\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 const employeeRepo = getRepository(Employee, tx)\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const newRecord = _createRecords[i]\n\n const supervisor =\n 'supervisor' in newRecord\n ? newRecord.supervisor && (await getRepository(Employee, tx).findOneBy({ id: newRecord.supervisor.id }))\n : undefined\n\n const department =\n 'department' in newRecord\n ? newRecord.department && (await getRepository(Department, tx).findOneBy({ id: newRecord.department.id }))\n : undefined\n\n const connectedUser =\n 'user' in newRecord\n ? newRecord.user && (await getRepository(User, tx).findOneBy({ id: newRecord.user.id }))\n : undefined\n\n const result = await employeeRepo.save({\n ...withDays(newRecord),\n supervisor,\n department,\n user: connectedUser,\n domain,\n creator: user,\n updater: user\n })\n\n if (newRecord.photo) {\n await createAttachment(\n null,\n {\n attachment: {\n file: newRecord.photo,\n refType: Employee.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const updateRecord = _updateRecords[i]\n\n const supervisor =\n 'supervisor' in updateRecord\n ? updateRecord.supervisor &&\n (await getRepository(Employee, tx).findOneBy({ id: updateRecord.supervisor.id }))\n : undefined\n\n const department =\n 'department' in updateRecord\n ? updateRecord.department &&\n (await getRepository(Department, tx).findOneBy({ id: updateRecord.department.id }))\n : undefined\n\n const connectedUser =\n 'user' in updateRecord\n ? updateRecord.user && (await getRepository(User, tx).findOneBy({ id: updateRecord.user.id }))\n : undefined\n\n const employee = await employeeRepo.findOne({\n where: { domain: { id: domain.id }, id: updateRecord.id }\n })\n\n if (!employee) {\n throw new Error(`failed to find employee to update: ${updateRecord.id}`)\n }\n\n await onUpdateEmployeeAsSystemUser(updateRecord, context)\n\n const result = await employeeRepo.save({\n ...employee,\n ...withDays(updateRecord),\n supervisor,\n department,\n user: connectedUser,\n updater: user\n })\n\n if (updateRecord.photo) {\n await deleteAttachmentsByRef(null, { refBys: [result.id] }, context)\n await createAttachment(\n null,\n {\n attachment: {\n file: updateRecord.photo,\n refType: Employee.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"employee\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Boolean, {\n description:\n 'Deletes an employee record identified by the given ID. Also deletes any attachments associated with the employee.'\n })\n async deleteEmployee(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await onDeleteEmployeeAsSystemUser(id, context)\n await getRepository(Employee, tx).delete({ domain: { id: domain.id }, id })\n await deleteAttachmentsByRef(null, { refBys: [id] }, context)\n\n return true\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"employee\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Boolean, {\n description:\n 'Deletes multiple employee records identified by the given IDs. Also deletes any attachments associated with each employee.'\n })\n async deleteEmployees(\n @Arg('ids', type => [String]) ids: string[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n for (let id of ids) {\n await onDeleteEmployeeAsSystemUser(id, context)\n }\n\n await getRepository(Employee, tx).delete({\n domain: { id: domain.id },\n id: In(ids)\n })\n\n await deleteAttachmentsByRef(null, { refBys: ids }, context)\n\n return true\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"employee\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Boolean, {\n description:\n 'Imports multiple employee records into the system. Each employee record must be provided in the EmployeePatch format.'\n })\n async importEmployees(\n @Arg('employees', type => [EmployeePatch]) employees: EmployeePatch[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n await Promise.all(\n employees.map(async (employee: EmployeePatch) => {\n const createdEmployee: Employee = await getRepository(Employee, tx).save({ domain, ...withDays(employee) })\n })\n )\n\n return true\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"employee\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Employee, {\n description:\n 'Attaches an existing contact to an employee. The contact is identified by its ID and the employee is identified by their ID.'\n })\n async attachContact(\n @Arg('id') id: string,\n @Arg('contactId') contactId: string,\n @Ctx() context: ResolverContext\n ): Promise<Employee> {\n const { domain, user, tx } = context.state\n\n const employeeRepository = getRepository(Employee, tx)\n const employee = await employeeRepository.findOne({\n where: { domain: { id: domain.id }, id }\n })\n\n const contactRepository = getRepository(Contact, tx)\n const contact = await contactRepository.findOne({\n where: { domain: { id: domain.id }, id: contactId }\n })\n\n if (!contact) {\n throw Error(`Contact not found with given contactId(${contactId}).`)\n }\n\n const result = await employeeRepository.save({\n ...employee,\n name: contact.name,\n contact: { id: contactId },\n updater: user\n })\n\n return result\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"employee\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Employee, {\n description: 'Detaches an existing contact from an employee. The employee is identified by their ID.'\n })\n async detachContact(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Employee> {\n const { domain, user, tx } = context.state\n\n const repository = getRepository(Employee, tx)\n const employee = await repository.findOne({\n where: { domain: { id: domain.id }, id }\n })\n\n const result = await repository.save({\n ...employee,\n contact: null,\n updater: user\n })\n\n return result\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"user\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Boolean, {\n description:\n 'Registers an existing employee as a system user, granting them access to the system. The employee is identified by their ID.'\n })\n async registerEmployeeAsSystemUser(\n @Arg('employeeId', { description: 'Employee Id' }) employeeId: string,\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n return !!(await registerEmployeeAsSystemUser(employeeId, context))\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"employee-mutation.js","sourceRoot":"","sources":["../../../server/service/employee/employee-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA4B;AAE5B,iDAAqD;AAErD,qEAA0F;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L,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,wBAAS,EAAC,mFAAmF,CAAC;IAC9F,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,mBAAQ,EAAE;QAC7B,WAAW,EACT,8HAA8H;KACjI,CAAC;IAEC,mBAAA,IAAA,kBAAG,EAAC,IAAI,CAAC,CAAA;IACT,mBAAA,IAAA,kBAAG,EAAC,WAAW,CAAC,CAAA;IAChB,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;qDA0BP;AAOK;IALL,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,wBAAS,EAAC,mFAAmF,CAAC;IAC9F,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,mBAAQ,EAAE;QAC7B,WAAW,EAAE,wFAAwF;KACtG,CAAC;IACmB,mBAAA,IAAA,kBAAG,EAAC,IAAI,CAAC,CAAA;IAAc,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;qDAehD;AAQK;IANL,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,wBAAS,EAAC,+EAA+E,CAAC;IAC1F,IAAA,uBAAQ,EAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE;QAC5B,WAAW,EACT,8HAA8H;KACjI,CAAC;IAEC,mBAAA,IAAA,kBAAG,EAAC,YAAY,EAAE,EAAE,WAAW,EAAE,aAAa,EAAE,CAAC,CAAA;IACjD,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;oEAGP;2BAvXU,gBAAgB;IAD5B,IAAA,uBAAQ,EAAC,mBAAQ,CAAC;GACN,gBAAgB,CAwX5B","sourcesContent":["import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { getRepository } from '@things-factory/shell'\nimport { User } from '@things-factory/auth-base'\nimport { createAttachment, deleteAttachmentsByRef } from '@things-factory/attachment-base'\nimport { Contact } from '@things-factory/contact'\n\nimport { Employee } from './employee'\nimport { NewEmployee, EmployeePatch } from './employee-type'\nimport { Department } from '../department/department'\nimport { withDays } from './employee-day'\nimport { referenceInDomain, userInDomain } from '../domain-reference'\n\nimport {\n onDeleteEmployeeAsSystemUser,\n onUpdateEmployeeAsSystemUser,\n registerEmployeeAsSystemUser\n} from '../../controllers/register-employee-as-system-user'\n\n@Resolver(Employee)\nexport class EmployeeMutation {\n @Directive('@transaction')\n @Directive('@privilege(category: \"employee\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Employee, {\n description:\n 'Creates a new employee record with the provided details. Optionally associates the employee with a supervisor, department, and system user. If a photo is provided, it will be attached to the employee record.'\n })\n async createEmployee(@Arg('employee') employee: NewEmployee, @Ctx() context: ResolverContext): Promise<Employee> {\n const { domain, user, tx } = context.state\n\n const supervisor = await referenceInDomain(\n getRepository(Employee, tx),\n 'supervisor' in employee ? employee.supervisor : undefined,\n domain,\n 'supervisor'\n )\n\n const department = await referenceInDomain(\n getRepository(Department, tx),\n 'department' in employee ? employee.department : undefined,\n domain,\n 'department'\n )\n\n const connectedUser = await userInDomain('user' in employee ? employee.user : undefined, domain, tx)\n\n const result = await getRepository(Employee, tx).save({\n ...withDays(employee),\n supervisor,\n department,\n user: connectedUser,\n domain,\n creator: user,\n updater: user\n })\n\n if (employee.photo) {\n await createAttachment(\n null,\n {\n attachment: {\n file: employee.photo,\n refType: Employee.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n return result\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"employee\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Employee, {\n description:\n 'Updates the details of an existing employee identified by the given ID. Optionally updates the supervisor, department, system user, and photo associated with the employee.'\n })\n async updateEmployee(\n @Arg('id') id: string,\n @Arg('patch') patch: EmployeePatch,\n @Ctx() context: ResolverContext\n ): Promise<Employee> {\n const { domain, user, tx } = context.state\n\n const supervisor = await referenceInDomain(\n getRepository(Employee, tx),\n 'supervisor' in patch ? patch.supervisor : undefined,\n domain,\n 'supervisor'\n )\n\n const department = await referenceInDomain(\n getRepository(Department, tx),\n 'department' in patch ? patch.department : undefined,\n domain,\n 'department'\n )\n\n const connectedUser = await userInDomain('user' in patch ? patch.user : undefined, domain, tx)\n\n const repository = getRepository(Employee, tx)\n const employee = await repository.findOne({\n where: { domain: { id: domain.id }, id }\n })\n\n await onUpdateEmployeeAsSystemUser(patch, context)\n\n const result = await repository.save({\n ...employee,\n ...withDays(patch),\n supervisor,\n department,\n user: connectedUser,\n updater: user\n })\n\n if (patch.photo) {\n await deleteAttachmentsByRef(null, { refBys: [result.id] }, context)\n await createAttachment(\n null,\n {\n attachment: {\n file: patch.photo,\n refType: Employee.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n return result\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"employee\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => [Employee], {\n description:\n 'Updates or creates multiple employee records based on the provided patches. New employees are created if the \"cuFlag\" is \"+\", and existing employees are updated if the \"cuFlag\" is \"M\".'\n })\n async updateMultipleEmployee(\n @Arg('patches', type => [EmployeePatch]) patches: EmployeePatch[],\n @Ctx() context: ResolverContext\n ): Promise<Employee[]> {\n const { domain, user, tx } = context.state\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 const employeeRepo = getRepository(Employee, tx)\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const newRecord = _createRecords[i]\n\n const supervisor = await referenceInDomain(\n getRepository(Employee, tx),\n 'supervisor' in newRecord ? newRecord.supervisor : undefined,\n domain,\n 'supervisor'\n )\n\n const department = await referenceInDomain(\n getRepository(Department, tx),\n 'department' in newRecord ? newRecord.department : undefined,\n domain,\n 'department'\n )\n\n const connectedUser = await userInDomain('user' in newRecord ? newRecord.user : undefined, domain, tx)\n\n const result = await employeeRepo.save({\n ...withDays(newRecord),\n supervisor,\n department,\n user: connectedUser,\n domain,\n creator: user,\n updater: user\n })\n\n if (newRecord.photo) {\n await createAttachment(\n null,\n {\n attachment: {\n file: newRecord.photo,\n refType: Employee.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n results.push({ ...result, cuFlag: '+' })\n }\n }\n\n if (_updateRecords.length > 0) {\n for (let i = 0; i < _updateRecords.length; i++) {\n const updateRecord = _updateRecords[i]\n\n const supervisor = await referenceInDomain(\n getRepository(Employee, tx),\n 'supervisor' in updateRecord ? updateRecord.supervisor : undefined,\n domain,\n 'supervisor'\n )\n\n const department = await referenceInDomain(\n getRepository(Department, tx),\n 'department' in updateRecord ? updateRecord.department : undefined,\n domain,\n 'department'\n )\n\n const connectedUser = await userInDomain('user' in updateRecord ? updateRecord.user : undefined, domain, tx)\n\n const employee = await employeeRepo.findOne({\n where: { domain: { id: domain.id }, id: updateRecord.id }\n })\n\n if (!employee) {\n throw new Error(`failed to find employee to update: ${updateRecord.id}`)\n }\n\n await onUpdateEmployeeAsSystemUser(updateRecord, context)\n\n const result = await employeeRepo.save({\n ...employee,\n ...withDays(updateRecord),\n supervisor,\n department,\n user: connectedUser,\n updater: user\n })\n\n if (updateRecord.photo) {\n await deleteAttachmentsByRef(null, { refBys: [result.id] }, context)\n await createAttachment(\n null,\n {\n attachment: {\n file: updateRecord.photo,\n refType: Employee.name,\n refBy: result.id\n }\n },\n context\n )\n }\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"employee\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Boolean, {\n description:\n 'Deletes an employee record identified by the given ID. Also deletes any attachments associated with the employee.'\n })\n async deleteEmployee(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await onDeleteEmployeeAsSystemUser(id, context)\n await getRepository(Employee, tx).delete({ domain: { id: domain.id }, id })\n await deleteAttachmentsByRef(null, { refBys: [id] }, context)\n\n return true\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"employee\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Boolean, {\n description:\n 'Deletes multiple employee records identified by the given IDs. Also deletes any attachments associated with each employee.'\n })\n async deleteEmployees(\n @Arg('ids', type => [String]) ids: string[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n for (let id of ids) {\n await onDeleteEmployeeAsSystemUser(id, context)\n }\n\n await getRepository(Employee, tx).delete({\n domain: { id: domain.id },\n id: In(ids)\n })\n\n await deleteAttachmentsByRef(null, { refBys: ids }, context)\n\n return true\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"employee\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Boolean, {\n description:\n 'Imports multiple employee records into the system. Each employee record must be provided in the EmployeePatch format.'\n })\n async importEmployees(\n @Arg('employees', type => [EmployeePatch]) employees: EmployeePatch[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n await Promise.all(\n employees.map(async (employee: EmployeePatch) => {\n const createdEmployee: Employee = await getRepository(Employee, tx).save({ domain, ...withDays(employee) })\n })\n )\n\n return true\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"employee\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Employee, {\n description:\n 'Attaches an existing contact to an employee. The contact is identified by its ID and the employee is identified by their ID.'\n })\n async attachContact(\n @Arg('id') id: string,\n @Arg('contactId') contactId: string,\n @Ctx() context: ResolverContext\n ): Promise<Employee> {\n const { domain, user, tx } = context.state\n\n const employeeRepository = getRepository(Employee, tx)\n const employee = await employeeRepository.findOne({\n where: { domain: { id: domain.id }, id }\n })\n\n const contactRepository = getRepository(Contact, tx)\n const contact = await contactRepository.findOne({\n where: { domain: { id: domain.id }, id: contactId }\n })\n\n if (!contact) {\n throw Error(`Contact not found with given contactId(${contactId}).`)\n }\n\n const result = await employeeRepository.save({\n ...employee,\n name: contact.name,\n contact: { id: contactId },\n updater: user\n })\n\n return result\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"employee\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Employee, {\n description: 'Detaches an existing contact from an employee. The employee is identified by their ID.'\n })\n async detachContact(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Employee> {\n const { domain, user, tx } = context.state\n\n const repository = getRepository(Employee, tx)\n const employee = await repository.findOne({\n where: { domain: { id: domain.id }, id }\n })\n\n const result = await repository.save({\n ...employee,\n contact: null,\n updater: user\n })\n\n return result\n }\n\n @Directive('@transaction')\n @Directive('@privilege(category: \"user\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Mutation(returns => Boolean, {\n description:\n 'Registers an existing employee as a system user, granting them access to the system. The employee is identified by their ID.'\n })\n async registerEmployeeAsSystemUser(\n @Arg('employeeId', { description: 'Employee Id' }) employeeId: string,\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n return !!(await registerEmployeeAsSystemUser(employeeId, context))\n }\n}\n"]}
|