@things-factory/pdf 10.1.122 → 10.1.131
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/README.md +19 -30
- package/dist-server/controller/pdf-document.d.ts +17 -0
- package/dist-server/controller/pdf-document.js +26 -0
- package/dist-server/controller/pdf-document.js.map +1 -0
- package/dist-server/controller/pdf-service.d.ts +2 -0
- package/dist-server/controller/pdf-service.js +40 -24
- package/dist-server/controller/pdf-service.js.map +1 -1
- package/dist-server/index.d.ts +0 -1
- package/dist-server/index.js +0 -1
- package/dist-server/index.js.map +1 -1
- package/dist-server/service/index.d.ts +1 -1
- package/dist-server/service/index.js +3 -4
- package/dist-server/service/index.js.map +1 -1
- package/dist-server/service/pdf-generate/index.d.ts +4 -0
- package/dist-server/service/pdf-generate/index.js +8 -0
- package/dist-server/service/pdf-generate/index.js.map +1 -0
- package/dist-server/service/pdf-generate/pdf-generate-resolver.d.ts +3 -2
- package/dist-server/service/pdf-generate/pdf-generate-resolver.js +37 -60
- package/dist-server/service/pdf-generate/pdf-generate-resolver.js.map +1 -1
- package/dist-server/service/pdf-release/pdf-release-mutation.js +6 -0
- package/dist-server/service/pdf-release/pdf-release-mutation.js.map +1 -1
- package/dist-server/service/pdf-release/pdf-release-query.d.ts +2 -0
- package/dist-server/service/pdf-release/pdf-release-query.js +13 -0
- package/dist-server/service/pdf-release/pdf-release-query.js.map +1 -1
- package/dist-server/service/pdf-release/pdf-release.d.ts +0 -2
- package/dist-server/service/pdf-release/pdf-release.js +1 -11
- package/dist-server/service/pdf-release/pdf-release.js.map +1 -1
- package/dist-server/service/pdf-template/pdf-template-mutation.js +6 -0
- package/dist-server/service/pdf-template/pdf-template-mutation.js.map +1 -1
- package/dist-server/service/pdf-template/pdf-template-query.js +2 -0
- package/dist-server/service/pdf-template/pdf-template-query.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -10
- package/translations/en.json +2 -1
- package/translations/ko.json +2 -1
- package/dist-server/routers/pdf-private-router.d.ts +0 -1
- package/dist-server/routers/pdf-private-router.js +0 -72
- package/dist-server/routers/pdf-private-router.js.map +0 -1
- package/dist-server/routers/pdf-public-router.d.ts +0 -1
- package/dist-server/routers/pdf-public-router.js +0 -66
- package/dist-server/routers/pdf-public-router.js.map +0 -1
- package/dist-server/routers/proxy-router.d.ts +0 -1
- package/dist-server/routers/proxy-router.js +0 -12
- package/dist-server/routers/proxy-router.js.map +0 -1
- package/dist-server/routes.d.ts +0 -1
- package/dist-server/routes.js +0 -21
- package/dist-server/routes.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,38 +1,27 @@
|
|
|
1
|
-
# pdf
|
|
1
|
+
# pdf
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Prints PDF documents from templates, for signed-in users with the `pdf` privilege. The module puts nothing on a
|
|
4
|
+
route; it is GraphQL only.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
- ubuntu [https://www.cyberciti.biz/faq/how-to-install-curl-command-on-a-ubuntu-linux/]
|
|
7
|
-
- MacOS [http://macappstore.org/curl/]
|
|
8
|
-
- ghostscript should be installed
|
|
9
|
-
- ubuntu [https://www.howtoinstall.me/ubuntu/18-04/ghostscript/]
|
|
10
|
-
- MacOS [http://macappstore.org/ghostscript/]
|
|
11
|
-
- [https://www.ghostscript.com/doc/current/Install.htm]
|
|
6
|
+
## templates (PDFTemplate)
|
|
12
7
|
|
|
13
|
-
|
|
8
|
+
Each part is a [Handlebars](https://handlebarsjs.com) template filled with the data given to the print —
|
|
9
|
+
Handlebars fills and escapes and runs no code.
|
|
14
10
|
|
|
15
|
-
|
|
11
|
+
| field | what it is |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| `content_template` | the body, as many pages as it takes |
|
|
14
|
+
| `cover_template` | a first page of its own |
|
|
15
|
+
| `last_template` | a last page of its own |
|
|
16
|
+
| `header_template` · `footer_template` | printed at the top and bottom of every page (`<span class="pageNumber"></span>` / `totalPages`) |
|
|
17
|
+
| `page_size` | A4 (default), A3, A5, Letter, Legal, Tabloid |
|
|
18
|
+
| `watermark` | text laid faintly across every page |
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
http://localhost:3000/pdf/to-png?url=http://www.africau.edu/images/default/sample.pdf
|
|
19
|
-
```
|
|
20
|
+
A page may load nothing but what it carries: put images in as `data:` URLs.
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
## printing
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
```
|
|
24
|
+
- `renderPDF(templateId, data)` — the PDF in base64, not kept (a preview).
|
|
25
|
+
- `generatePDF(templateId, data)` — prints and keeps a `PDFRelease`; its `file` is the PDF as an attachment.
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
```
|
|
30
|
-
http://localhost:3000/pdf/merge
|
|
31
|
-
body:
|
|
32
|
-
{
|
|
33
|
-
"urls":[
|
|
34
|
-
"http://www.africau.edu/images/default/sample.pdf",
|
|
35
|
-
"https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"
|
|
36
|
-
]
|
|
37
|
-
}
|
|
38
|
-
```
|
|
27
|
+
Pages are printed in a headless browser from the shell's pool `pdf` (`HEADLESS_POOL_PDF_MAX`, default 4).
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface PdfTemplateParts {
|
|
2
|
+
content_template?: string | null;
|
|
3
|
+
header_template?: string | null;
|
|
4
|
+
footer_template?: string | null;
|
|
5
|
+
cover_template?: string | null;
|
|
6
|
+
last_template?: string | null;
|
|
7
|
+
page_size?: string | null;
|
|
8
|
+
watermark?: string | null;
|
|
9
|
+
}
|
|
10
|
+
export interface PdfDocument {
|
|
11
|
+
html: string;
|
|
12
|
+
format: string;
|
|
13
|
+
headerTemplate?: string;
|
|
14
|
+
footerTemplate?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare const PAGE_SIZES: string[];
|
|
17
|
+
export declare function composePdfDocument(template: PdfTemplateParts, data: any): PdfDocument;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PAGE_SIZES = void 0;
|
|
4
|
+
exports.composePdfDocument = composePdfDocument;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const handlebars_1 = tslib_1.__importDefault(require("handlebars"));
|
|
7
|
+
exports.PAGE_SIZES = ['A3', 'A4', 'A5', 'Letter', 'Legal', 'Tabloid'];
|
|
8
|
+
const fill = (template, data) => (template ? handlebars_1.default.compile(template)(data ?? {}) : '');
|
|
9
|
+
const escape = (text) => text.replace(/[&<>"]/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"' })[c]);
|
|
10
|
+
function composePdfDocument(template, data) {
|
|
11
|
+
const format = exports.PAGE_SIZES.find(size => size.toLowerCase() === String(template.page_size ?? '').trim().toLowerCase()) ?? 'A4';
|
|
12
|
+
const pages = [fill(template.cover_template, data), fill(template.content_template, data), fill(template.last_template, data)].filter(Boolean);
|
|
13
|
+
const watermark = template.watermark?.trim();
|
|
14
|
+
const html = `<!doctype html><html><head><meta charset="utf-8"><style>
|
|
15
|
+
@page { size: ${format} }
|
|
16
|
+
.pdf-page-break { break-after: page }
|
|
17
|
+
.pdf-watermark { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none;
|
|
18
|
+
font: 700 72pt sans-serif; color: rgba(0, 0, 0, .08); transform: rotate(-30deg); z-index: 1000 }
|
|
19
|
+
</style></head><body>${watermark ? `<div class="pdf-watermark">${escape(watermark)}</div>` : ''}${pages
|
|
20
|
+
.map((page, i) => (i < pages.length - 1 ? `<div class="pdf-page-break">${page}</div>` : page))
|
|
21
|
+
.join('')}</body></html>`;
|
|
22
|
+
const header = fill(template.header_template, data);
|
|
23
|
+
const footer = fill(template.footer_template, data);
|
|
24
|
+
return { html, format, ...(header ? { headerTemplate: header } : {}), ...(footer ? { footerTemplate: footer } : {}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C,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;IAC9I,MAAM,SAAS,GAAG,QAAQ,CAAC,SAAS,EAAE,IAAI,EAAE,CAAA;IAC5C,MAAM,IAAI,GAAG;gBACC,MAAM;;;;uBAIC,SAAS,CAAC,CAAC,CAAC,8BAA8B,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK;SAClG,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,+BAA+B,IAAI,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;SAC7F,IAAI,CAAC,EAAE,CAAC,gBAAgB,CAAA;IAC3B,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,eAAe,EAAE,IAAI,CAAC,CAAA;IACnD,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,eAAe,EAAE,IAAI,CAAC,CAAA;IACnD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAA;AACvH,CAAC","sourcesContent":["import Handlebars from 'handlebars'\n\n/*\n * A PDF template as one printable page set — pure: no browser, no database.\n *\n * Each part of a template is a Handlebars template filled with the request's data. Handlebars only fills and\n * escapes; unlike ejs it runs no code, so whoever writes a template cannot run anything on the server.\n *\n * cover_template a first page of its own\n * content_template the body, as many pages as it takes\n * last_template a last page of its own\n * header_template printed at the top of every page (the browser's header, with pageNumber / totalPages)\n * footer_template printed at the bottom of every page\n * page_size A4 (default), A3, A5, Letter, Legal or Tabloid\n * watermark text laid faintly across every page\n */\n\nexport interface PdfTemplateParts {\n content_template?: string | null\n header_template?: string | null\n footer_template?: string | null\n cover_template?: string | null\n last_template?: string | null\n page_size?: string | null\n watermark?: string | null\n}\n\nexport interface PdfDocument {\n html: string\n format: string\n headerTemplate?: string\n footerTemplate?: string\n}\n\nexport const PAGE_SIZES = ['A3', 'A4', 'A5', 'Letter', 'Legal', 'Tabloid']\n\nconst fill = (template: string | null | undefined, data: any) => (template ? Handlebars.compile(template)(data ?? {}) : '')\nconst escape = (text: string) => text.replace(/[&<>\"]/g, c => ({ '&': '&', '<': '<', '>': '>', '\"': '"' })[c]!)\n\nexport function composePdfDocument(template: PdfTemplateParts, data: any): PdfDocument {\n const format = PAGE_SIZES.find(size => size.toLowerCase() === String(template.page_size ?? '').trim().toLowerCase()) ?? 'A4'\n const pages = [fill(template.cover_template, data), fill(template.content_template, data), fill(template.last_template, data)].filter(Boolean)\n const watermark = template.watermark?.trim()\n const html = `<!doctype html><html><head><meta charset=\"utf-8\"><style>\n@page { size: ${format} }\n.pdf-page-break { break-after: page }\n.pdf-watermark { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none;\n font: 700 72pt sans-serif; color: rgba(0, 0, 0, .08); transform: rotate(-30deg); z-index: 1000 }\n</style></head><body>${watermark ? `<div class=\"pdf-watermark\">${escape(watermark)}</div>` : ''}${pages\n .map((page, i) => (i < pages.length - 1 ? `<div class=\"pdf-page-break\">${page}</div>` : page))\n .join('')}</body></html>`\n const header = fill(template.header_template, data)\n const footer = fill(template.footer_template, data)\n return { html, format, ...(header ? { headerTemplate: header } : {}), ...(footer ? { footerTemplate: footer } : {}) }\n}\n"]}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { PDFTemplate } from '../service/pdf-template/pdf-template';
|
|
2
|
+
/** Whether the page may load a request — only what it carries. */
|
|
3
|
+
export declare const loadsOnly: (url: string) => boolean;
|
|
2
4
|
export declare class PdfService {
|
|
3
5
|
generatePdf(template: PDFTemplate, data: any): Promise<Buffer>;
|
|
4
6
|
}
|
|
@@ -1,33 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PdfService = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
3
|
+
exports.PdfService = exports.loadsOnly = void 0;
|
|
4
|
+
const shell_1 = require("@things-factory/shell");
|
|
5
|
+
const pdf_document_1 = require("./pdf-document");
|
|
6
|
+
/*
|
|
7
|
+
* A template filled and printed to PDF in a headless browser from the shell's pool, as board-service prints a
|
|
8
|
+
* board. No browser stays idle (min 0); the first print after a while waits a second or two.
|
|
9
|
+
*
|
|
10
|
+
* The page may load nothing but what it carries (data: URLs): a template that pointed at an address would make
|
|
11
|
+
* the server fetch it.
|
|
12
|
+
*/
|
|
13
|
+
const pool = (0, shell_1.getOrCreateHeadlessPool)('pdf', {
|
|
14
|
+
min: 0,
|
|
15
|
+
max: parseInt(process.env.HEADLESS_POOL_PDF_MAX ?? '4', 10),
|
|
16
|
+
args: [...shell_1.HEADLESS_POOL_ARGUMENT_SETS.basic, ...shell_1.HEADLESS_POOL_ARGUMENT_SETS.keychain_safe],
|
|
17
|
+
acquireTimeoutMillis: 15000,
|
|
18
|
+
testOnBorrow: true,
|
|
19
|
+
enableCleanup: true
|
|
20
|
+
});
|
|
21
|
+
/** Whether the page may load a request — only what it carries. */
|
|
22
|
+
const loadsOnly = (url) => url.startsWith('data:') || url === 'about:blank';
|
|
23
|
+
exports.loadsOnly = loadsOnly;
|
|
7
24
|
class PdfService {
|
|
8
25
|
async generatePdf(template, data) {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
const document = (0, pdf_document_1.composePdfDocument)(template, data);
|
|
27
|
+
const browser = await pool.acquire();
|
|
28
|
+
const page = await browser.newPage();
|
|
29
|
+
try {
|
|
30
|
+
await page.setRequestInterception(true);
|
|
31
|
+
page.on('request', (request) => ((0, exports.loadsOnly)(request.url()) ? request.continue() : request.abort()));
|
|
32
|
+
await page.setContent(document.html, { waitUntil: 'load' });
|
|
33
|
+
const framed = !!(document.headerTemplate || document.footerTemplate);
|
|
34
|
+
return Buffer.from(await page.pdf({
|
|
35
|
+
format: document.format,
|
|
36
|
+
printBackground: true,
|
|
37
|
+
displayHeaderFooter: framed,
|
|
38
|
+
headerTemplate: document.headerTemplate ?? '<span></span>',
|
|
39
|
+
footerTemplate: document.footerTemplate ?? '<span></span>',
|
|
40
|
+
...(framed ? { margin: { top: '20mm', bottom: '20mm', left: '12mm', right: '12mm' } } : { preferCSSPageSize: true })
|
|
41
|
+
}));
|
|
24
42
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
43
|
+
finally {
|
|
44
|
+
await page.close().catch(() => { });
|
|
45
|
+
await pool.release(browser);
|
|
28
46
|
}
|
|
29
|
-
const pdfBytes = await pdfDoc.save();
|
|
30
|
-
return Buffer.from(pdfBytes);
|
|
31
47
|
}
|
|
32
48
|
}
|
|
33
49
|
exports.PdfService = PdfService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pdf-service.js","sourceRoot":"","sources":["../../server/controller/pdf-service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pdf-service.js","sourceRoot":"","sources":["../../server/controller/pdf-service.ts"],"names":[],"mappings":";;;AAAA,iDAA4F;AAG5F,iDAAmD;AAEnD;;;;;;GAMG;AACH,MAAM,IAAI,GAAG,IAAA,+BAAuB,EAAC,KAAK,EAAE;IAC1C,GAAG,EAAE,CAAC;IACN,GAAG,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,GAAG,EAAE,EAAE,CAAC;IAC3D,IAAI,EAAE,C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BACrB,mBAAmB,EAAE,MAAM;gBAC3B,cAAc,EAAE,QAAQ,CAAC,cAAc,IAAI,eAAe;gBAC1D,cAAc,EAAE,QAAQ,CAAC,cAAc,IAAI,eAAe;gBAC1D,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC;aACrH,CAAC,CACH,CAAA;QACH,CAAC;gBAAS,CAAC;YACT,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;YAClC,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAC7B,CAAC;IACH,CAAC;CACF;AAzBD,gCAyBC","sourcesContent":["import { getOrCreateHeadlessPool, HEADLESS_POOL_ARGUMENT_SETS } from '@things-factory/shell'\n\nimport { PDFTemplate } from '../service/pdf-template/pdf-template'\nimport { composePdfDocument } from './pdf-document'\n\n/*\n * A template filled and printed to PDF in a headless browser from the shell's pool, as board-service prints a\n * board. No browser stays idle (min 0); the first print after a while waits a second or two.\n *\n * The page may load nothing but what it carries (data: URLs): a template that pointed at an address would make\n * the server fetch it.\n */\nconst pool = getOrCreateHeadlessPool('pdf', {\n min: 0,\n max: parseInt(process.env.HEADLESS_POOL_PDF_MAX ?? '4', 10),\n args: [...HEADLESS_POOL_ARGUMENT_SETS.basic, ...HEADLESS_POOL_ARGUMENT_SETS.keychain_safe],\n acquireTimeoutMillis: 15000,\n testOnBorrow: true,\n enableCleanup: true\n})\n\n/** Whether the page may load a request — only what it carries. */\nexport const loadsOnly = (url: string) => url.startsWith('data:') || url === 'about:blank'\n\nexport class PdfService {\n async generatePdf(template: PDFTemplate, data: any): Promise<Buffer> {\n const document = composePdfDocument(template, data)\n const browser: any = await pool.acquire()\n const page = await browser.newPage()\n try {\n await page.setRequestInterception(true)\n page.on('request', (request: any) => (loadsOnly(request.url()) ? request.continue() : request.abort()))\n await page.setContent(document.html, { waitUntil: 'load' })\n const framed = !!(document.headerTemplate || document.footerTemplate)\n return Buffer.from(\n await page.pdf({\n format: document.format,\n printBackground: true,\n displayHeaderFooter: framed,\n headerTemplate: document.headerTemplate ?? '<span></span>',\n footerTemplate: document.footerTemplate ?? '<span></span>',\n ...(framed ? { margin: { top: '20mm', bottom: '20mm', left: '12mm', right: '12mm' } } : { preferCSSPageSize: true })\n })\n )\n } finally {\n await page.close().catch(() => {})\n await pool.release(browser)\n }\n }\n}\n"]}
|
package/dist-server/index.d.ts
CHANGED
package/dist-server/index.js
CHANGED
package/dist-server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;AAAA,oDAAyB
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;AAAA,oDAAyB","sourcesContent":["export * from './service'\n\n"]}
|
|
@@ -3,5 +3,5 @@ export * from './pdf-template/pdf-template';
|
|
|
3
3
|
export declare const entities: (typeof import("./pdf-template/pdf-template").PDFTemplate | typeof import("./pdf-release/pdf-release").PDFRelease)[];
|
|
4
4
|
export declare const subscribers: any[];
|
|
5
5
|
export declare const schema: {
|
|
6
|
-
resolverClasses: (typeof import("./pdf-release/pdf-release-query").PDFReleaseQuery | typeof import("./pdf-release/pdf-release-mutation").PDFReleaseMutation | typeof import("./pdf-template/pdf-template-query").PDFTemplateQuery | typeof import("./pdf-template/pdf-template-mutation").PDFTemplateMutation)[];
|
|
6
|
+
resolverClasses: (typeof import("./pdf-release/pdf-release-query").PDFReleaseQuery | typeof import("./pdf-release/pdf-release-mutation").PDFReleaseMutation | typeof import("./pdf-generate/pdf-generate-resolver").PDFGenerateResolver | typeof import("./pdf-template/pdf-template-query").PDFTemplateQuery | typeof import("./pdf-template/pdf-template-mutation").PDFTemplateMutation)[];
|
|
7
7
|
};
|
|
@@ -7,25 +7,24 @@ tslib_1.__exportStar(require("./pdf-release/pdf-release"), exports);
|
|
|
7
7
|
tslib_1.__exportStar(require("./pdf-template/pdf-template"), exports);
|
|
8
8
|
/* IMPORT ENTITIES AND RESOLVERS */
|
|
9
9
|
const pdf_release_1 = require("./pdf-release");
|
|
10
|
+
const pdf_generate_1 = require("./pdf-generate");
|
|
10
11
|
const pdf_template_1 = require("./pdf-template");
|
|
11
12
|
exports.entities = [
|
|
12
13
|
/* ENTITIES */
|
|
13
14
|
...pdf_release_1.entities,
|
|
14
|
-
...pdf_release_1.entities,
|
|
15
15
|
...pdf_template_1.entities
|
|
16
16
|
];
|
|
17
17
|
exports.subscribers = [
|
|
18
18
|
/* SUBSCRIBERS */
|
|
19
19
|
...pdf_release_1.subscribers,
|
|
20
|
-
...pdf_release_1.subscribers,
|
|
21
20
|
...pdf_template_1.subscribers
|
|
22
21
|
];
|
|
23
22
|
exports.schema = {
|
|
24
23
|
resolverClasses: [
|
|
25
24
|
/* RESOLVER CLASSES */
|
|
26
25
|
...pdf_release_1.resolvers,
|
|
27
|
-
...
|
|
28
|
-
...
|
|
26
|
+
...pdf_template_1.resolvers,
|
|
27
|
+
...pdf_generate_1.resolvers
|
|
29
28
|
]
|
|
30
29
|
};
|
|
31
30
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/service/index.ts"],"names":[],"mappings":";;;;AAAA,yBAAyB;AACzB,oEAAyC;AACzC,sEAA2C;AAE3C,mCAAmC;AACnC,+CAIsB;AACtB,iDAIuB;AAEV,QAAA,QAAQ,GAAG;IACtB,cAAc;IACd,GAAG,sBAAkB;IACrB,GAAG,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/service/index.ts"],"names":[],"mappings":";;;;AAAA,yBAAyB;AACzB,oEAAyC;AACzC,sEAA2C;AAE3C,mCAAmC;AACnC,+CAIsB;AACtB,iDAAkE;AAClE,iDAIuB;AAEV,QAAA,QAAQ,GAAG;IACtB,cAAc;IACd,GAAG,sBAAkB;IACrB,GAAG,uBAAmB;CACvB,CAAA;AAEY,QAAA,WAAW,GAAG;IACzB,iBAAiB;IACjB,GAAG,yBAAqB;IACxB,GAAG,0BAAsB;CAC1B,CAAA;AAEY,QAAA,MAAM,GAAG;IACpB,eAAe,EAAE;QACf,sBAAsB;QACtB,GAAG,uBAAmB;QACtB,GAAG,wBAAoB;QACvB,GAAG,wBAAoB;KACxB;CACF,CAAA","sourcesContent":["/* EXPORT ENTITY TYPES */\nexport * from './pdf-release/pdf-release'\nexport * from './pdf-template/pdf-template'\n\n/* IMPORT ENTITIES AND RESOLVERS */\nimport {\n entities as PdfReleaseEntities,\n resolvers as PdfReleaseResolvers,\n subscribers as PdfReleaseSubscribers\n} from './pdf-release'\nimport { resolvers as PDFGenerateResolvers } from './pdf-generate'\nimport {\n entities as PDFTemplateEntities,\n resolvers as PDFTemplateResolvers,\n subscribers as PDFTemplateSubscribers\n} from './pdf-template'\n\nexport const entities = [\n /* ENTITIES */\n ...PdfReleaseEntities,\n ...PDFTemplateEntities\n]\n\nexport const subscribers = [\n /* SUBSCRIBERS */\n ...PdfReleaseSubscribers,\n ...PDFTemplateSubscribers\n]\n\nexport const schema = {\n resolverClasses: [\n /* RESOLVER CLASSES */\n ...PdfReleaseResolvers,\n ...PDFTemplateResolvers,\n ...PDFGenerateResolvers\n ]\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.subscribers = exports.resolvers = exports.entities = void 0;
|
|
4
|
+
const pdf_generate_resolver_1 = require("./pdf-generate-resolver");
|
|
5
|
+
exports.entities = [];
|
|
6
|
+
exports.resolvers = [pdf_generate_resolver_1.PDFGenerateResolver];
|
|
7
|
+
exports.subscribers = [];
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../server/service/pdf-generate/index.ts"],"names":[],"mappings":";;;AAAA,mEAA6D;AAEhD,QAAA,QAAQ,GAAG,EAAE,CAAA;AACb,QAAA,SAAS,GAAG,CAAC,2CAAmB,CAAC,CAAA;AACjC,QAAA,WAAW,GAAG,EAAE,CAAA","sourcesContent":["import { PDFGenerateResolver } from './pdf-generate-resolver'\n\nexport const entities = []\nexport const resolvers = [PDFGenerateResolver]\nexport const subscribers = []\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PDFRelease } from '../pdf-release/pdf-release';
|
|
2
2
|
export declare class PDFGenerateResolver {
|
|
3
3
|
private pdfService;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
private templateOf;
|
|
5
|
+
renderPDF(templateId: string, data: any, context: ResolverContext): Promise<string>;
|
|
6
|
+
generatePDF(templateId: string, data: any, context: ResolverContext): Promise<PDFRelease>;
|
|
6
7
|
}
|
|
@@ -2,86 +2,63 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PDFGenerateResolver = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const stream_1 = require("stream");
|
|
5
6
|
const type_graphql_1 = require("type-graphql");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
7
|
+
const attachment_base_1 = require("@things-factory/attachment-base");
|
|
8
|
+
const shell_1 = require("@things-factory/shell");
|
|
9
|
+
const pdf_service_1 = require("../../controller/pdf-service");
|
|
8
10
|
const pdf_release_1 = require("../pdf-release/pdf-release");
|
|
9
11
|
const pdf_template_1 = require("../pdf-template/pdf-template");
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const PDF_STORAGE_PATH = '/path/to/pdf/storage'; // 실제 파일 저장 경로
|
|
13
|
-
const PDF_BASE_URL = 'https://yourdomain.com/pdf/'; // 파일 접근 URL의 기본 경로
|
|
12
|
+
/** A generated PDF handed to the attachment store as an upload would be. */
|
|
13
|
+
const upload = (filename, contents) => Promise.resolve({ filename, mimetype: 'application/pdf', encoding: '7bit', createReadStream: () => stream_1.Readable.from([contents]) });
|
|
14
14
|
let PDFGenerateResolver = class PDFGenerateResolver {
|
|
15
15
|
constructor() {
|
|
16
16
|
this.pdfService = new pdf_service_1.PdfService();
|
|
17
17
|
}
|
|
18
|
-
async
|
|
19
|
-
const { domain,
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
throw new Error('PDF Template not found');
|
|
25
|
-
}
|
|
26
|
-
var state = pdf_release_1.PDFReleaseStatus.published;
|
|
27
|
-
try {
|
|
28
|
-
const pdfBuffer = await this.pdfService.generatePdf(template, data);
|
|
29
|
-
const fileName = `${template.name}-${Date.now()}.pdf`;
|
|
30
|
-
const filePath = path.join(PDF_STORAGE_PATH, fileName);
|
|
31
|
-
const fileUrl = `${PDF_BASE_URL}${fileName}`;
|
|
32
|
-
fs.writeFileSync(filePath, pdfBuffer);
|
|
33
|
-
return releaseRepository.save({
|
|
34
|
-
template,
|
|
35
|
-
filePath,
|
|
36
|
-
fileUrl,
|
|
37
|
-
state,
|
|
38
|
-
creator: user,
|
|
39
|
-
updater: user,
|
|
40
|
-
domain
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
state = pdf_release_1.PDFReleaseStatus.failed;
|
|
45
|
-
return releaseRepository.save({
|
|
46
|
-
template,
|
|
47
|
-
state,
|
|
48
|
-
creator: user,
|
|
49
|
-
updater: user,
|
|
50
|
-
domain
|
|
51
|
-
});
|
|
52
|
-
}
|
|
18
|
+
async templateOf(context, templateId) {
|
|
19
|
+
const { domain, tx } = context.state;
|
|
20
|
+
const template = await tx.getRepository(pdf_template_1.PDFTemplate).findOne({ where: { id: templateId, domain: { id: domain.id } } });
|
|
21
|
+
if (!template)
|
|
22
|
+
throw new Error(context.t('error.pdf-template-not-found'));
|
|
23
|
+
return template;
|
|
53
24
|
}
|
|
54
|
-
async
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
await (
|
|
64
|
-
|
|
25
|
+
async renderPDF(templateId, data, context) {
|
|
26
|
+
return (await this.pdfService.generatePdf(await this.templateOf(context, templateId), data)).toString('base64');
|
|
27
|
+
}
|
|
28
|
+
async generatePDF(templateId, data, context) {
|
|
29
|
+
const { domain, user, tx } = context.state;
|
|
30
|
+
const template = await this.templateOf(context, templateId);
|
|
31
|
+
const repository = tx.getRepository(pdf_release_1.PDFRelease);
|
|
32
|
+
const name = `${template.name}-${Date.now()}`;
|
|
33
|
+
const contents = await this.pdfService.generatePdf(template, data);
|
|
34
|
+
const release = await repository.save({ domain, name, template, state: pdf_release_1.PDFReleaseStatus.published, creator: user, updater: user });
|
|
35
|
+
await (0, attachment_base_1.createAttachment)(null, { attachment: { file: upload(`${name}.pdf`, contents), refType: 'PDFRelease', refBy: release.id, category: 'document' } }, context);
|
|
36
|
+
return release;
|
|
65
37
|
}
|
|
66
38
|
};
|
|
67
39
|
exports.PDFGenerateResolver = PDFGenerateResolver;
|
|
68
40
|
tslib_1.__decorate([
|
|
69
|
-
(0, type_graphql_1.
|
|
41
|
+
(0, type_graphql_1.Directive)('@privilege(category: "pdf", privilege: "query", domainOwnerGranted: true)'),
|
|
42
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
|
43
|
+
(0, type_graphql_1.Query)(() => String, { description: 'To print a template with data to a PDF without keeping it — base64, for a preview' }),
|
|
70
44
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('templateId')),
|
|
71
|
-
tslib_1.__param(1, (0, type_graphql_1.Arg)('data')),
|
|
45
|
+
tslib_1.__param(1, (0, type_graphql_1.Arg)('data', type => shell_1.ScalarObject, { nullable: true })),
|
|
72
46
|
tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
|
|
73
47
|
tslib_1.__metadata("design:type", Function),
|
|
74
48
|
tslib_1.__metadata("design:paramtypes", [String, Object, Object]),
|
|
75
49
|
tslib_1.__metadata("design:returntype", Promise)
|
|
76
|
-
], PDFGenerateResolver.prototype, "
|
|
50
|
+
], PDFGenerateResolver.prototype, "renderPDF", null);
|
|
77
51
|
tslib_1.__decorate([
|
|
78
|
-
(0, type_graphql_1.
|
|
79
|
-
|
|
80
|
-
|
|
52
|
+
(0, type_graphql_1.Directive)('@privilege(category: "pdf", privilege: "mutation", domainOwnerGranted: true)'),
|
|
53
|
+
(0, type_graphql_1.Directive)('@transaction'),
|
|
54
|
+
(0, type_graphql_1.Mutation)(() => pdf_release_1.PDFRelease, { description: 'To print a template with data to a PDF and keep it as a release — its file is an attachment of the release' }),
|
|
55
|
+
tslib_1.__param(0, (0, type_graphql_1.Arg)('templateId')),
|
|
56
|
+
tslib_1.__param(1, (0, type_graphql_1.Arg)('data', type => shell_1.ScalarObject, { nullable: true })),
|
|
57
|
+
tslib_1.__param(2, (0, type_graphql_1.Ctx)()),
|
|
81
58
|
tslib_1.__metadata("design:type", Function),
|
|
82
|
-
tslib_1.__metadata("design:paramtypes", [String, Object]),
|
|
59
|
+
tslib_1.__metadata("design:paramtypes", [String, Object, Object]),
|
|
83
60
|
tslib_1.__metadata("design:returntype", Promise)
|
|
84
|
-
], PDFGenerateResolver.prototype, "
|
|
61
|
+
], PDFGenerateResolver.prototype, "generatePDF", null);
|
|
85
62
|
exports.PDFGenerateResolver = PDFGenerateResolver = tslib_1.__decorate([
|
|
86
63
|
(0, type_graphql_1.Resolver)()
|
|
87
64
|
], PDFGenerateResolver);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pdf-generate-resolver.js","sourceRoot":"","sources":["../../../server/service/pdf-generate/pdf-generate-resolver.ts"],"names":[],"mappings":";;;;AAAA,+
|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,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,mFAAmF,EAAE,CAAC;IACzG,mBAAA,IAAA,kBAAG,EAAC,YAAY,CAAC,CAAA;IAAsB,mBAAA,IAAA,kBAAG,EAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,oBAAY,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;IAAa,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;oDAE9H;AAKK;IAHL,IAAA,wBAAS,EAAC,8EAA8E,CAAC;IACzF,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,IAAA,uBAAQ,EAAC,GAAG,EAAE,CAAC,wBAAU,EAAE,EAAE,WAAW,EAAE,4GAA4G,EAAE,CAAC;IACvI,mBAAA,IAAA,kBAAG,EAAC,YAAY,CAAC,CAAA;IAAsB,mBAAA,IAAA,kBAAG,EAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,oBAAY,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAA;IAAa,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;sDAShI;8BA7BU,mBAAmB;IAD/B,IAAA,uBAAQ,GAAE;GACE,mBAAmB,CA8B/B","sourcesContent":["import { Readable } from 'stream'\nimport { Arg, Ctx, Directive, Mutation, Query, Resolver } from 'type-graphql'\n\nimport { createAttachment } from '@things-factory/attachment-base'\nimport { ScalarObject } from '@things-factory/shell'\n\nimport { PdfService } from '../../controller/pdf-service'\nimport { PDFRelease, PDFReleaseStatus } from '../pdf-release/pdf-release'\nimport { PDFTemplate } from '../pdf-template/pdf-template'\n\n/** A generated PDF handed to the attachment store as an upload would be. */\nconst upload = (filename: string, contents: Buffer) =>\n Promise.resolve({ filename, mimetype: 'application/pdf', encoding: '7bit', createReadStream: () => Readable.from([contents]) })\n\n@Resolver()\nexport class PDFGenerateResolver {\n private pdfService = new PdfService()\n\n private async templateOf(context: ResolverContext, templateId: string): Promise<PDFTemplate> {\n const { domain, tx } = context.state\n const template = await tx.getRepository(PDFTemplate).findOne({ where: { id: templateId, domain: { id: domain.id } } })\n if (!template) throw new Error(context.t('error.pdf-template-not-found'))\n return template\n }\n\n @Directive('@privilege(category: \"pdf\", privilege: \"query\", domainOwnerGranted: true)')\n @Directive('@transaction')\n @Query(() => String, { description: 'To print a template with data to a PDF without keeping it — base64, for a preview' })\n async renderPDF(@Arg('templateId') templateId: string, @Arg('data', type => ScalarObject, { nullable: true }) data: any, @Ctx() context: ResolverContext): Promise<string> {\n return (await this.pdfService.generatePdf(await this.templateOf(context, templateId), data)).toString('base64')\n }\n\n @Directive('@privilege(category: \"pdf\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Directive('@transaction')\n @Mutation(() => PDFRelease, { description: 'To print a template with data to a PDF and keep it as a release — its file is an attachment of the release' })\n async generatePDF(@Arg('templateId') templateId: string, @Arg('data', type => ScalarObject, { nullable: true }) data: any, @Ctx() context: ResolverContext): Promise<PDFRelease> {\n const { domain, user, tx } = context.state\n const template = await this.templateOf(context, templateId)\n const repository = tx.getRepository(PDFRelease)\n const name = `${template.name}-${Date.now()}`\n const contents = await this.pdfService.generatePdf(template, data)\n const release = await repository.save({ domain, name, template, state: PDFReleaseStatus.published, creator: user, updater: user })\n await createAttachment(null, { attachment: { file: upload(`${name}.pdf`, contents), refType: 'PDFRelease', refBy: release.id, category: 'document' } }, context)\n return release\n }\n}\n"]}
|
|
@@ -90,6 +90,7 @@ let PDFReleaseMutation = class PDFReleaseMutation {
|
|
|
90
90
|
};
|
|
91
91
|
exports.PDFReleaseMutation = PDFReleaseMutation;
|
|
92
92
|
tslib_1.__decorate([
|
|
93
|
+
(0, type_graphql_1.Directive)('@privilege(category: "pdf", privilege: "mutation", domainOwnerGranted: true)'),
|
|
93
94
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
94
95
|
(0, type_graphql_1.Mutation)(returns => pdf_release_1.PDFRelease, { description: 'To create new PDFRelease' }),
|
|
95
96
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('pdfRelease')),
|
|
@@ -99,6 +100,7 @@ tslib_1.__decorate([
|
|
|
99
100
|
tslib_1.__metadata("design:returntype", Promise)
|
|
100
101
|
], PDFReleaseMutation.prototype, "createPDFRelease", null);
|
|
101
102
|
tslib_1.__decorate([
|
|
103
|
+
(0, type_graphql_1.Directive)('@privilege(category: "pdf", privilege: "mutation", domainOwnerGranted: true)'),
|
|
102
104
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
103
105
|
(0, type_graphql_1.Mutation)(returns => pdf_release_1.PDFRelease, { description: 'To modify PDFRelease information' }),
|
|
104
106
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
@@ -109,6 +111,7 @@ tslib_1.__decorate([
|
|
|
109
111
|
tslib_1.__metadata("design:returntype", Promise)
|
|
110
112
|
], PDFReleaseMutation.prototype, "updatePDFRelease", null);
|
|
111
113
|
tslib_1.__decorate([
|
|
114
|
+
(0, type_graphql_1.Directive)('@privilege(category: "pdf", privilege: "mutation", domainOwnerGranted: true)'),
|
|
112
115
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
113
116
|
(0, type_graphql_1.Mutation)(returns => [pdf_release_1.PDFRelease], { description: "To modify multiple PDFReleases' information" }),
|
|
114
117
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('patches', type => [pdf_release_type_1.PDFReleasePatch])),
|
|
@@ -118,6 +121,7 @@ tslib_1.__decorate([
|
|
|
118
121
|
tslib_1.__metadata("design:returntype", Promise)
|
|
119
122
|
], PDFReleaseMutation.prototype, "updateMultiplePDFRelease", null);
|
|
120
123
|
tslib_1.__decorate([
|
|
124
|
+
(0, type_graphql_1.Directive)('@privilege(category: "pdf", privilege: "mutation", domainOwnerGranted: true)'),
|
|
121
125
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
122
126
|
(0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To delete PDFRelease' }),
|
|
123
127
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('id')),
|
|
@@ -127,6 +131,7 @@ tslib_1.__decorate([
|
|
|
127
131
|
tslib_1.__metadata("design:returntype", Promise)
|
|
128
132
|
], PDFReleaseMutation.prototype, "deletePDFRelease", null);
|
|
129
133
|
tslib_1.__decorate([
|
|
134
|
+
(0, type_graphql_1.Directive)('@privilege(category: "pdf", privilege: "mutation", domainOwnerGranted: true)'),
|
|
130
135
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
131
136
|
(0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To delete multiple PDFReleases' }),
|
|
132
137
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('ids', type => [String])),
|
|
@@ -136,6 +141,7 @@ tslib_1.__decorate([
|
|
|
136
141
|
tslib_1.__metadata("design:returntype", Promise)
|
|
137
142
|
], PDFReleaseMutation.prototype, "deletePDFReleases", null);
|
|
138
143
|
tslib_1.__decorate([
|
|
144
|
+
(0, type_graphql_1.Directive)('@privilege(category: "pdf", privilege: "mutation", domainOwnerGranted: true)'),
|
|
139
145
|
(0, type_graphql_1.Directive)('@transaction'),
|
|
140
146
|
(0, type_graphql_1.Mutation)(returns => Boolean, { description: 'To import multiple PDFReleases' }),
|
|
141
147
|
tslib_1.__param(0, (0, type_graphql_1.Arg)('pdfReleases', type => [pdf_release_type_1.PDFReleasePatch])),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pdf-release-mutation.js","sourceRoot":"","sources":["../../../server/service/pdf-release/pdf-release-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA4B;AAE5B,+CAA0C;AAC1C,yDAAmE;AAG5D,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAGvB,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,MAAM,GAAG,MAAM,EAAE,CAAC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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;;;;2DAUP;AAIK;IAFL,IAAA,wBAAS,EAAC,cAAc,CAAC;IACzB,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,kCAAe,CAAC,CAAC,CAAA;IAC7C,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;2DAWP;6BAvIU,kBAAkB;IAD9B,IAAA,uBAAQ,EAAC,wBAAU,CAAC;GACR,kBAAkB,CAwI9B","sourcesContent":["import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { PDFRelease } from './pdf-release'\nimport { NewPDFRelease, PDFReleasePatch } from './pdf-release-type'\n\n@Resolver(PDFRelease)\nexport class PDFReleaseMutation {\n @Directive('@transaction')\n @Mutation(returns => PDFRelease, { description: 'To create new PDFRelease' })\n async createPDFRelease(\n @Arg('pdfRelease') pdfRelease: NewPDFRelease,\n @Ctx() context: ResolverContext\n ): Promise<PDFRelease> {\n const { domain, user, tx } = context.state\n\n const result = await tx.getRepository(PDFRelease).save({\n ...pdfRelease,\n domain,\n creator: user,\n updater: user\n })\n\n return result\n }\n\n @Directive('@transaction')\n @Mutation(returns => PDFRelease, { description: 'To modify PDFRelease information' })\n async updatePDFRelease(\n @Arg('id') id: string,\n @Arg('patch') patch: PDFReleasePatch,\n @Ctx() context: ResolverContext\n ): Promise<PDFRelease> {\n const { domain, user, tx } = context.state\n\n const repository = tx.getRepository(PDFRelease)\n const pdfRelease = await repository.findOne({\n where: { domain: { id: domain.id }, id }\n })\n\n const result = await repository.save({\n ...pdfRelease,\n ...patch,\n updater: user\n })\n\n return result\n }\n\n @Directive('@transaction')\n @Mutation(returns => [PDFRelease], { description: \"To modify multiple PDFReleases' information\" })\n async updateMultiplePDFRelease(\n @Arg('patches', type => [PDFReleasePatch]) patches: PDFReleasePatch[],\n @Ctx() context: ResolverContext\n ): Promise<PDFRelease[]> {\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 pdfReleaseRepo = tx.getRepository(PDFRelease)\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const newRecord = _createRecords[i]\n\n const result = await pdfReleaseRepo.save({\n ...newRecord,\n domain,\n creator: user,\n updater: user\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 pdfRelease = await pdfReleaseRepo.findOne({\n where: { domain: { id: domain.id }, id: updateRecord.id }\n })\n\n if (!pdfRelease) {\n throw new Error(`failed to find pdfRelease to update: ${updateRecord.id}`)\n }\n\n const result = await pdfReleaseRepo.save({\n ...pdfRelease,\n ...updateRecord,\n updater: user\n })\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete PDFRelease' })\n async deletePDFRelease(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(PDFRelease).delete({ domain: { id: domain.id }, id })\n\n return true\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete multiple PDFReleases' })\n async deletePDFReleases(\n @Arg('ids', type => [String]) ids: string[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(PDFRelease).delete({\n domain: { id: domain.id },\n id: In(ids)\n })\n\n return true\n }\n\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To import multiple PDFReleases' })\n async importPDFReleases(\n @Arg('pdfReleases', type => [PDFReleasePatch]) pdfReleases: PDFReleasePatch[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n await Promise.all(\n pdfReleases.map(async (pdfRelease: PDFReleasePatch) => {\n const createdPDFRelease: PDFRelease = await tx.getRepository(PDFRelease).save({ domain, ...pdfRelease })\n })\n )\n\n return true\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pdf-release-mutation.js","sourceRoot":"","sources":["../../../server/service/pdf-release/pdf-release-mutation.ts"],"names":[],"mappings":";;;;AAAA,+CAAsE;AACtE,qCAA4B;AAE5B,+CAA0C;AAC1C,yDAAmE;AAG5D,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,MAAM,GAAG,MAAM,EAAE,CAAC,aAAa,CAAC,wBAAU,CAAC,CAAC,IAAI,CAAC;YACrD,GAAG,UAAU;YACb,MAAM;YACN,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,IAAI;SACd,CAAC,CAAA;QAEF,OAAO,MAAM,CAAA;IACf,CAAC;IAKK,AAAN,KAAK,CAAC,gBAAgB,CACT,EAAU,EACP,KAAsB,EAC7B,OAAwB;QAE/B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAE1C,MAAM,UAAU,GAAG,EAAE,CAAC,aAAa,CAAC,wBAAU,CAAC,CAAA;QAC/C,MAAM,UAAU,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC;YAC1C,KAAK,EA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AAc,CAAC;IACzB,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,kCAAe,CAAC,CAAC,CAAA;IAC7C,mBAAA,IAAA,kBAAG,GAAE,CAAA;;;;2DAWP;6BA7IU,kBAAkB;IAD9B,IAAA,uBAAQ,EAAC,wBAAU,CAAC;GACR,kBAAkB,CA8I9B","sourcesContent":["import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'\nimport { In } from 'typeorm'\n\nimport { PDFRelease } from './pdf-release'\nimport { NewPDFRelease, PDFReleasePatch } from './pdf-release-type'\n\n@Resolver(PDFRelease)\nexport class PDFReleaseMutation {\n @Directive('@privilege(category: \"pdf\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Directive('@transaction')\n @Mutation(returns => PDFRelease, { description: 'To create new PDFRelease' })\n async createPDFRelease(\n @Arg('pdfRelease') pdfRelease: NewPDFRelease,\n @Ctx() context: ResolverContext\n ): Promise<PDFRelease> {\n const { domain, user, tx } = context.state\n\n const result = await tx.getRepository(PDFRelease).save({\n ...pdfRelease,\n domain,\n creator: user,\n updater: user\n })\n\n return result\n }\n\n @Directive('@privilege(category: \"pdf\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Directive('@transaction')\n @Mutation(returns => PDFRelease, { description: 'To modify PDFRelease information' })\n async updatePDFRelease(\n @Arg('id') id: string,\n @Arg('patch') patch: PDFReleasePatch,\n @Ctx() context: ResolverContext\n ): Promise<PDFRelease> {\n const { domain, user, tx } = context.state\n\n const repository = tx.getRepository(PDFRelease)\n const pdfRelease = await repository.findOne({\n where: { domain: { id: domain.id }, id }\n })\n\n const result = await repository.save({\n ...pdfRelease,\n ...patch,\n updater: user\n })\n\n return result\n }\n\n @Directive('@privilege(category: \"pdf\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Directive('@transaction')\n @Mutation(returns => [PDFRelease], { description: \"To modify multiple PDFReleases' information\" })\n async updateMultiplePDFRelease(\n @Arg('patches', type => [PDFReleasePatch]) patches: PDFReleasePatch[],\n @Ctx() context: ResolverContext\n ): Promise<PDFRelease[]> {\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 pdfReleaseRepo = tx.getRepository(PDFRelease)\n\n if (_createRecords.length > 0) {\n for (let i = 0; i < _createRecords.length; i++) {\n const newRecord = _createRecords[i]\n\n const result = await pdfReleaseRepo.save({\n ...newRecord,\n domain,\n creator: user,\n updater: user\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 pdfRelease = await pdfReleaseRepo.findOne({\n where: { domain: { id: domain.id }, id: updateRecord.id }\n })\n\n if (!pdfRelease) {\n throw new Error(`failed to find pdfRelease to update: ${updateRecord.id}`)\n }\n\n const result = await pdfReleaseRepo.save({\n ...pdfRelease,\n ...updateRecord,\n updater: user\n })\n\n results.push({ ...result, cuFlag: 'M' })\n }\n }\n\n return results\n }\n\n @Directive('@privilege(category: \"pdf\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete PDFRelease' })\n async deletePDFRelease(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(PDFRelease).delete({ domain: { id: domain.id }, id })\n\n return true\n }\n\n @Directive('@privilege(category: \"pdf\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To delete multiple PDFReleases' })\n async deletePDFReleases(\n @Arg('ids', type => [String]) ids: string[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n await tx.getRepository(PDFRelease).delete({\n domain: { id: domain.id },\n id: In(ids)\n })\n\n return true\n }\n\n @Directive('@privilege(category: \"pdf\", privilege: \"mutation\", domainOwnerGranted: true)')\n @Directive('@transaction')\n @Mutation(returns => Boolean, { description: 'To import multiple PDFReleases' })\n async importPDFReleases(\n @Arg('pdfReleases', type => [PDFReleasePatch]) pdfReleases: PDFReleasePatch[],\n @Ctx() context: ResolverContext\n ): Promise<boolean> {\n const { domain, tx } = context.state\n\n await Promise.all(\n pdfReleases.map(async (pdfRelease: PDFReleasePatch) => {\n const createdPDFRelease: PDFRelease = await tx.getRepository(PDFRelease).save({ domain, ...pdfRelease })\n })\n )\n\n return true\n }\n}\n"]}
|