@things-factory/pdf 7.0.28 → 7.0.36
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/client/bootstrap.js +6 -0
- package/client/pages/pdf-template/pdf-template-importer.ts +86 -0
- package/client/pages/pdf-template/pdf-template-list-page.ts +491 -0
- package/client/route.ts +7 -0
- package/client/tsconfig.json +13 -0
- package/dist-client/bootstrap.d.ts +1 -0
- package/dist-client/bootstrap.js +6 -0
- package/dist-client/bootstrap.js.map +1 -0
- package/dist-client/pages/pdf-template/pdf-template-importer.d.ts +23 -0
- package/dist-client/pages/pdf-template/pdf-template-importer.js +93 -0
- package/dist-client/pages/pdf-template/pdf-template-importer.js.map +1 -0
- package/dist-client/pages/pdf-template/pdf-template-list-page.d.ts +66 -0
- package/dist-client/pages/pdf-template/pdf-template-list-page.js +464 -0
- package/dist-client/pages/pdf-template/pdf-template-list-page.js.map +1 -0
- package/dist-client/route.d.ts +1 -0
- package/dist-client/route.js +8 -0
- package/dist-client/route.js.map +1 -0
- package/dist-client/tsconfig.tsbuildinfo +1 -0
- package/dist-server/index.d.ts +1 -0
- package/dist-server/index.js +2 -0
- package/dist-server/index.js.map +1 -1
- package/dist-server/routers/pdf-private-router.d.ts +1 -0
- package/dist-server/routers/pdf-private-router.js +25 -0
- package/dist-server/routers/pdf-private-router.js.map +1 -0
- package/dist-server/routers/pdf-public-router.d.ts +1 -0
- package/dist-server/routers/{pdf-router.js → pdf-public-router.js} +6 -6
- package/dist-server/routers/pdf-public-router.js.map +1 -0
- package/dist-server/routes.js +13 -2
- package/dist-server/routes.js.map +1 -1
- package/dist-server/service/index.d.ts +6 -0
- package/dist-server/service/index.js +23 -0
- package/dist-server/service/index.js.map +1 -0
- package/dist-server/service/pdf-template/index.d.ts +6 -0
- package/dist-server/service/pdf-template/index.js +10 -0
- package/dist-server/service/pdf-template/index.js.map +1 -0
- package/dist-server/service/pdf-template/pdf-template-mutation.d.ts +10 -0
- package/dist-server/service/pdf-template/pdf-template-mutation.js +127 -0
- package/dist-server/service/pdf-template/pdf-template-mutation.js.map +1 -0
- package/dist-server/service/pdf-template/pdf-template-query.d.ts +11 -0
- package/dist-server/service/pdf-template/pdf-template-query.js +79 -0
- package/dist-server/service/pdf-template/pdf-template-query.js.map +1 -0
- package/dist-server/service/pdf-template/pdf-template-type.d.ts +32 -0
- package/dist-server/service/pdf-template/pdf-template-type.js +125 -0
- package/dist-server/service/pdf-template/pdf-template-type.js.map +1 -0
- package/dist-server/service/pdf-template/pdf-template.d.ts +28 -0
- package/dist-server/service/pdf-template/pdf-template.js +125 -0
- package/dist-server/service/pdf-template/pdf-template.js.map +1 -0
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/helps/pdf/pdf-template.md +160 -0
- package/package.json +14 -9
- package/server/index.ts +2 -0
- package/server/routers/pdf-private-router.ts +24 -0
- package/server/routers/{pdf-router.ts → pdf-public-router.ts} +4 -4
- package/server/routes.ts +14 -2
- package/server/service/index.ts +26 -0
- package/server/service/pdf-template/index.ts +7 -0
- package/server/service/pdf-template/pdf-template-mutation.ts +138 -0
- package/server/service/pdf-template/pdf-template-query.ts +51 -0
- package/server/service/pdf-template/pdf-template-type.ts +87 -0
- package/server/service/pdf-template/pdf-template.ts +108 -0
- package/server/tsconfig.json +10 -0
- package/things-factory.config.js +8 -1
- package/translations/en.json +11 -0
- package/translations/ja.json +9 -0
- package/translations/ko.json +11 -0
- package/translations/ms.json +9 -0
- package/translations/zh.json +9 -0
- package/dist-server/routers/pdf-router.d.ts +0 -1
- package/dist-server/routers/pdf-router.js.map +0 -1
- package/tsconfig.json +0 -9
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# PdfTemplate
|
|
2
|
+
|
|
3
|
+
Paragraphs are separated by a blank line.
|
|
4
|
+
|
|
5
|
+
2nd paragraph. _Italic_, **bold**, and `monospace`. Itemized lists
|
|
6
|
+
look like:
|
|
7
|
+
|
|
8
|
+
- this one
|
|
9
|
+
- that one
|
|
10
|
+
- the other one
|
|
11
|
+
|
|
12
|
+
Note that --- not considering the asterisk --- the actual text
|
|
13
|
+
content starts at 4-columns in.
|
|
14
|
+
|
|
15
|
+
> Block quotes are
|
|
16
|
+
> written like so.
|
|
17
|
+
>
|
|
18
|
+
> They can span multiple paragraphs,
|
|
19
|
+
> if you like.
|
|
20
|
+
|
|
21
|
+
Use 3 dashes for an em-dash. Use 2 dashes for ranges (ex., "it's all
|
|
22
|
+
in chapters 12--14"). Three dots ... will be converted to an ellipsis.
|
|
23
|
+
Unicode is supported. ☺
|
|
24
|
+
|
|
25
|
+
## An h2 header
|
|
26
|
+
|
|
27
|
+
Here's a numbered list:
|
|
28
|
+
|
|
29
|
+
1. first item
|
|
30
|
+
2. second item
|
|
31
|
+
3. third item
|
|
32
|
+
|
|
33
|
+
Note again how the actual text starts at 4 columns in (4 characters
|
|
34
|
+
from the left side). Here's a code sample:
|
|
35
|
+
|
|
36
|
+
# Let me re-iterate ...
|
|
37
|
+
|
|
38
|
+
for i in 1 .. 10 { do-something(i) }
|
|
39
|
+
|
|
40
|
+
As you probably guessed, indented 4 spaces. By the way, instead of
|
|
41
|
+
indenting the block, you can use delimited blocks, if you like:
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
define foobar() {
|
|
45
|
+
print "Welcome to flavor country!";
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
(which makes copying & pasting easier). You can optionally mark the
|
|
50
|
+
delimited block for Pandoc to syntax highlight it:
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import time
|
|
54
|
+
# Quick, count to ten!
|
|
55
|
+
for i in range(10):
|
|
56
|
+
# (but not *too* quick)
|
|
57
|
+
time.sleep(0.5)
|
|
58
|
+
print(i)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### An h3 header
|
|
62
|
+
|
|
63
|
+
Now a nested list:
|
|
64
|
+
|
|
65
|
+
1. First, get these ingredients:
|
|
66
|
+
|
|
67
|
+
- carrots
|
|
68
|
+
- celery
|
|
69
|
+
- lentils
|
|
70
|
+
|
|
71
|
+
2. Boil some water.
|
|
72
|
+
|
|
73
|
+
3. Dump everything in the pot and follow
|
|
74
|
+
this algorithm:
|
|
75
|
+
|
|
76
|
+
find wooden spoon
|
|
77
|
+
uncover pot
|
|
78
|
+
stir
|
|
79
|
+
cover pot
|
|
80
|
+
balance wooden spoon precariously on pot handle
|
|
81
|
+
wait 10 minutes
|
|
82
|
+
goto first step (or shut off burner when done)
|
|
83
|
+
|
|
84
|
+
Do not bump wooden spoon or it will fall.
|
|
85
|
+
|
|
86
|
+
Notice again how text always lines up on 4-space indents (including
|
|
87
|
+
that last line which continues item 3 above).
|
|
88
|
+
|
|
89
|
+
Here's a link to [a website](http://foo.bar), to a [local
|
|
90
|
+
doc](local-doc.html), and to a [section heading in the current
|
|
91
|
+
doc](#an-h2-header). Here's a footnote [^1].
|
|
92
|
+
|
|
93
|
+
[^1]: Some footnote text.
|
|
94
|
+
|
|
95
|
+
Tables can look like this:
|
|
96
|
+
|
|
97
|
+
Name Size Material Color
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
All Business 9 leather brown
|
|
102
|
+
Roundabout 10 hemp canvas natural
|
|
103
|
+
Cinderella 11 glass transparent
|
|
104
|
+
|
|
105
|
+
Table: Shoes sizes, materials, and colors.
|
|
106
|
+
|
|
107
|
+
(The above is the caption for the table.) Pandoc also supports
|
|
108
|
+
multi-line tables:
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
Keyword Text
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
red Sunsets, apples, and
|
|
117
|
+
other red or reddish
|
|
118
|
+
things.
|
|
119
|
+
|
|
120
|
+
green Leaves, grass, frogs
|
|
121
|
+
and other things it's
|
|
122
|
+
not easy being.
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
A horizontal rule follows.
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
Here's a definition list:
|
|
131
|
+
|
|
132
|
+
apples
|
|
133
|
+
: Good for making applesauce.
|
|
134
|
+
|
|
135
|
+
oranges
|
|
136
|
+
: Citrus!
|
|
137
|
+
|
|
138
|
+
tomatoes
|
|
139
|
+
: There's no "e" in tomatoe.
|
|
140
|
+
|
|
141
|
+
Again, text is indented 4 spaces. (Put a blank line between each
|
|
142
|
+
term and its definition to spread things out more.)
|
|
143
|
+
|
|
144
|
+
Here's a "line block" (note how whitespace is honored):
|
|
145
|
+
|
|
146
|
+
| Line one
|
|
147
|
+
| Line too
|
|
148
|
+
| Line tree
|
|
149
|
+
|
|
150
|
+
and images can be specified like so:
|
|
151
|
+
|
|
152
|
+

|
|
153
|
+
|
|
154
|
+
Inline math equation: $\omega = d\phi / dt$. Display
|
|
155
|
+
math should get its own line like so:
|
|
156
|
+
|
|
157
|
+
$$I = \int \rho R^{2} dV$$
|
|
158
|
+
|
|
159
|
+
And note that you can backslash-escape any punctuation characters
|
|
160
|
+
which you wish to be displayed literally, ex.: \`foo\`, \*bar\*, etc.
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/pdf",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.36",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
|
+
"browser": "dist-client/index.js",
|
|
5
6
|
"things-factory": true,
|
|
6
7
|
"author": "heartyoh <heartyoh@hatiolab.com>",
|
|
7
8
|
"description": "Module that provide services for merging pdf files and extracting image from pdf.",
|
|
@@ -16,15 +17,19 @@
|
|
|
16
17
|
"directory": "packages/pdf"
|
|
17
18
|
},
|
|
18
19
|
"scripts": {
|
|
19
|
-
"build": "
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
20
|
+
"build": "npm run build:server && npm run build:client",
|
|
21
|
+
"copy:files": "copyfiles -e \"./client/**/*.{ts,js,json}\" -u 1 \"./client/**/*\" dist-client",
|
|
22
|
+
"build:client": "npm run copy:files && npx tsc --p ./client/tsconfig.json",
|
|
23
|
+
"build:server": "npx tsc --p ./server/tsconfig.json",
|
|
24
|
+
"clean:client": "npx rimraf dist-client",
|
|
25
|
+
"clean:server": "npx rimraf dist-server",
|
|
26
|
+
"clean": "npm run clean:server && npm run clean:client"
|
|
24
27
|
},
|
|
25
28
|
"dependencies": {
|
|
26
|
-
"@things-factory/
|
|
27
|
-
"
|
|
29
|
+
"@things-factory/auth-base": "^7.0.33",
|
|
30
|
+
"@things-factory/utils": "^7.0.33",
|
|
31
|
+
"await-spawn": "^4.0.1",
|
|
32
|
+
"handlebars": "^4.7.8"
|
|
28
33
|
},
|
|
29
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "f9ac274d234e8ba1d67a994953bc63e4ab758b79"
|
|
30
35
|
}
|
package/server/index.ts
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import Router from 'koa-router'
|
|
2
|
+
|
|
3
|
+
export const pdfPrivateRouter = new Router()
|
|
4
|
+
|
|
5
|
+
function parseQuery(query) {
|
|
6
|
+
for (const key in query) {
|
|
7
|
+
if (query.hasOwnProperty(key)) {
|
|
8
|
+
try {
|
|
9
|
+
query[key] = JSON.parse(query[key])
|
|
10
|
+
} catch (error) {
|
|
11
|
+
// do nothing
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return query
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
pdfPrivateRouter.post('/pdf-download', async (context, next) => {
|
|
20
|
+
let { id, model, base } = context.request.body
|
|
21
|
+
const data = parseQuery({ ...context.query })
|
|
22
|
+
|
|
23
|
+
await context.render('pdf-download', { id, model, data, base })
|
|
24
|
+
})
|
|
@@ -4,10 +4,10 @@ import Router from 'koa-router'
|
|
|
4
4
|
import path from 'path'
|
|
5
5
|
import { withTempDir } from '@things-factory/utils'
|
|
6
6
|
|
|
7
|
-
export const
|
|
7
|
+
export const pdfPublicRouter = new Router()
|
|
8
8
|
|
|
9
9
|
/* to-png */
|
|
10
|
-
|
|
10
|
+
pdfPublicRouter.get('/to-png', async (context, next) => {
|
|
11
11
|
const { url } = context.query
|
|
12
12
|
|
|
13
13
|
const images = await withTempDir(async tmpDir => {
|
|
@@ -60,7 +60,7 @@ const mergePDFfiles = async urls => {
|
|
|
60
60
|
})
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
pdfPublicRouter.get('/merge', async (context, next) => {
|
|
64
64
|
const searchParams = new URLSearchParams(context.querystring)
|
|
65
65
|
const urls = searchParams.getAll('urls')
|
|
66
66
|
|
|
@@ -70,7 +70,7 @@ pdfRouter.get('/merge', async (context, next) => {
|
|
|
70
70
|
context.body = pdf
|
|
71
71
|
})
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
pdfPublicRouter.post('/merge', async (context, next) => {
|
|
74
74
|
const { urls } = context.request.body
|
|
75
75
|
|
|
76
76
|
const pdf = await mergePDFfiles(urls)
|
package/server/routes.ts
CHANGED
|
@@ -1,7 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { config } from '@things-factory/env'
|
|
2
|
+
import { pdfPublicRouter } from './routers/pdf-public-router'
|
|
3
|
+
import { pdfPrivateRouter } from './routers/pdf-private-router'
|
|
2
4
|
import { proxyRouter } from './routers/proxy-router'
|
|
3
5
|
|
|
6
|
+
const isPathBaseDomain = !config.get('subdomain') && !config.get('useVirtualHostBasedDomain')
|
|
7
|
+
|
|
4
8
|
process.on('bootstrap-module-global-public-route' as any, (app, globalPublicRouter) => {
|
|
5
|
-
globalPublicRouter.use('/pdf',
|
|
9
|
+
globalPublicRouter.use('/pdf', pdfPublicRouter.routes(), pdfPublicRouter.allowedMethods())
|
|
6
10
|
globalPublicRouter.use('/proxy', proxyRouter.routes(), proxyRouter.allowedMethods())
|
|
7
11
|
})
|
|
12
|
+
|
|
13
|
+
process.on('bootstrap-module-domain-private-route' as any, (app, domainPrivateRouter) => {
|
|
14
|
+
if (isPathBaseDomain) {
|
|
15
|
+
domainPrivateRouter.use('/domain/:domain', pdfPrivateRouter.routes(), pdfPrivateRouter.allowedMethods())
|
|
16
|
+
} else {
|
|
17
|
+
domainPrivateRouter.use('', pdfPrivateRouter.routes(), pdfPrivateRouter.allowedMethods())
|
|
18
|
+
}
|
|
19
|
+
})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* EXPORT ENTITY TYPES */
|
|
2
|
+
export * from './pdf-template/pdf-template'
|
|
3
|
+
|
|
4
|
+
/* IMPORT ENTITIES AND RESOLVERS */
|
|
5
|
+
import {
|
|
6
|
+
entities as PDFTemplateEntities,
|
|
7
|
+
resolvers as PDFTemplateResolvers,
|
|
8
|
+
subscribers as PDFTemplateSubscribers
|
|
9
|
+
} from './pdf-template'
|
|
10
|
+
|
|
11
|
+
export const entities = [
|
|
12
|
+
/* ENTITIES */
|
|
13
|
+
...PDFTemplateEntities
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
export const subscribers = [
|
|
17
|
+
/* SUBSCRIBERS */
|
|
18
|
+
...PDFTemplateSubscribers
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
export const schema = {
|
|
22
|
+
resolverClasses: [
|
|
23
|
+
/* RESOLVER CLASSES */
|
|
24
|
+
...PDFTemplateResolvers
|
|
25
|
+
]
|
|
26
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PDFTemplate } from './pdf-template'
|
|
2
|
+
import { PDFTemplateQuery } from './pdf-template-query'
|
|
3
|
+
import { PDFTemplateMutation } from './pdf-template-mutation'
|
|
4
|
+
|
|
5
|
+
export const entities = [PDFTemplate]
|
|
6
|
+
export const resolvers = [PDFTemplateQuery, PDFTemplateMutation]
|
|
7
|
+
export const subscribers = []
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'
|
|
2
|
+
import { In } from 'typeorm'
|
|
3
|
+
|
|
4
|
+
import { PDFTemplate } from './pdf-template'
|
|
5
|
+
import { NewPDFTemplate, PDFTemplatePatch } from './pdf-template-type'
|
|
6
|
+
|
|
7
|
+
@Resolver(PDFTemplate)
|
|
8
|
+
export class PDFTemplateMutation {
|
|
9
|
+
@Directive('@transaction')
|
|
10
|
+
@Mutation(returns => PDFTemplate, { description: 'To create new PDFTemplate' })
|
|
11
|
+
async createPDFTemplate(
|
|
12
|
+
@Arg('pdfTemplate') pdfTemplate: NewPDFTemplate,
|
|
13
|
+
@Ctx() context: ResolverContext
|
|
14
|
+
): Promise<PDFTemplate> {
|
|
15
|
+
const { domain, user, tx } = context.state
|
|
16
|
+
|
|
17
|
+
const result = await tx.getRepository(PDFTemplate).save({
|
|
18
|
+
...pdfTemplate,
|
|
19
|
+
domain,
|
|
20
|
+
creator: user,
|
|
21
|
+
updater: user
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
return result
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@Directive('@transaction')
|
|
28
|
+
@Mutation(returns => PDFTemplate, { description: 'To modify PDFTemplate information' })
|
|
29
|
+
async updatePDFTemplate(
|
|
30
|
+
@Arg('id') id: string,
|
|
31
|
+
@Arg('patch') patch: PDFTemplatePatch,
|
|
32
|
+
@Ctx() context: ResolverContext
|
|
33
|
+
): Promise<PDFTemplate> {
|
|
34
|
+
const { domain, user, tx } = context.state
|
|
35
|
+
|
|
36
|
+
const repository = tx.getRepository(PDFTemplate)
|
|
37
|
+
const pdfTemplate = await repository.findOne({
|
|
38
|
+
where: { domain: { id: domain.id }, id }
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const result = await repository.save({
|
|
42
|
+
...pdfTemplate,
|
|
43
|
+
...patch,
|
|
44
|
+
updater: user
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
return result
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@Directive('@transaction')
|
|
51
|
+
@Mutation(returns => [PDFTemplate], { description: "To modify multiple PDFTemplates' information" })
|
|
52
|
+
async updateMultiplePDFTemplate(
|
|
53
|
+
@Arg('patches', type => [PDFTemplatePatch]) patches: PDFTemplatePatch[],
|
|
54
|
+
@Ctx() context: ResolverContext
|
|
55
|
+
): Promise<PDFTemplate[]> {
|
|
56
|
+
const { domain, user, tx } = context.state
|
|
57
|
+
|
|
58
|
+
let results = []
|
|
59
|
+
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
60
|
+
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
61
|
+
const pdfTemplateRepo = tx.getRepository(PDFTemplate)
|
|
62
|
+
|
|
63
|
+
if (_createRecords.length > 0) {
|
|
64
|
+
for (let i = 0; i < _createRecords.length; i++) {
|
|
65
|
+
const newRecord = _createRecords[i]
|
|
66
|
+
|
|
67
|
+
const result = await pdfTemplateRepo.save({
|
|
68
|
+
...newRecord,
|
|
69
|
+
domain,
|
|
70
|
+
creator: user,
|
|
71
|
+
updater: user
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
results.push({ ...result, cuFlag: '+' })
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (_updateRecords.length > 0) {
|
|
79
|
+
for (let i = 0; i < _updateRecords.length; i++) {
|
|
80
|
+
const updateRecord = _updateRecords[i]
|
|
81
|
+
const pdfTemplate = await pdfTemplateRepo.findOneBy({ id: updateRecord.id })
|
|
82
|
+
|
|
83
|
+
const result = await pdfTemplateRepo.save({
|
|
84
|
+
...pdfTemplate,
|
|
85
|
+
...updateRecord,
|
|
86
|
+
updater: user
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
results.push({ ...result, cuFlag: 'M' })
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return results
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@Directive('@transaction')
|
|
97
|
+
@Mutation(returns => Boolean, { description: 'To delete PDFTemplate' })
|
|
98
|
+
async deletePDFTemplate(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
|
|
99
|
+
const { domain, tx } = context.state
|
|
100
|
+
|
|
101
|
+
await tx.getRepository(PDFTemplate).delete({ domain: { id: domain.id }, id })
|
|
102
|
+
|
|
103
|
+
return true
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@Directive('@transaction')
|
|
107
|
+
@Mutation(returns => Boolean, { description: 'To delete multiple PDFTemplates' })
|
|
108
|
+
async deletePDFTemplates(
|
|
109
|
+
@Arg('ids', type => [String]) ids: string[],
|
|
110
|
+
@Ctx() context: ResolverContext
|
|
111
|
+
): Promise<boolean> {
|
|
112
|
+
const { domain, tx } = context.state
|
|
113
|
+
|
|
114
|
+
await tx.getRepository(PDFTemplate).delete({
|
|
115
|
+
domain: { id: domain.id },
|
|
116
|
+
id: In(ids)
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
return true
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
@Directive('@transaction')
|
|
123
|
+
@Mutation(returns => Boolean, { description: 'To import multiple PDFTemplates' })
|
|
124
|
+
async importPDFTemplates(
|
|
125
|
+
@Arg('pdfTemplates', type => [PDFTemplatePatch]) pdfTemplates: PDFTemplatePatch[],
|
|
126
|
+
@Ctx() context: ResolverContext
|
|
127
|
+
): Promise<boolean> {
|
|
128
|
+
const { domain, tx } = context.state
|
|
129
|
+
|
|
130
|
+
await Promise.all(
|
|
131
|
+
pdfTemplates.map(async (pdfTemplate: PDFTemplatePatch) => {
|
|
132
|
+
const createdPDFTemplate: PDFTemplate = await tx.getRepository(PDFTemplate).save({ domain, ...pdfTemplate })
|
|
133
|
+
})
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
return true
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Resolver, Query, FieldResolver, Root, Args, Arg, Ctx, Directive } from 'type-graphql'
|
|
2
|
+
import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
|
|
3
|
+
import { User } from '@things-factory/auth-base'
|
|
4
|
+
import { PDFTemplate } from './pdf-template'
|
|
5
|
+
import { PDFTemplateList } from './pdf-template-type'
|
|
6
|
+
|
|
7
|
+
@Resolver(PDFTemplate)
|
|
8
|
+
export class PDFTemplateQuery {
|
|
9
|
+
@Query(returns => PDFTemplate!, { nullable: true, description: 'To fetch a PDFTemplate' })
|
|
10
|
+
async PDFTemplate(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<PDFTemplate> {
|
|
11
|
+
const { domain } = context.state
|
|
12
|
+
|
|
13
|
+
return await getRepository(PDFTemplate).findOne({
|
|
14
|
+
where: { domain: { id: domain.id }, id }
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@Query(returns => PDFTemplateList, { description: 'To fetch multiple PDFTemplates' })
|
|
19
|
+
async PDFTemplates(
|
|
20
|
+
@Args(type => ListParam) params: ListParam,
|
|
21
|
+
@Ctx() context: ResolverContext
|
|
22
|
+
): Promise<PDFTemplateList> {
|
|
23
|
+
const { domain } = context.state
|
|
24
|
+
|
|
25
|
+
const queryBuilder = getQueryBuilderFromListParams({
|
|
26
|
+
domain,
|
|
27
|
+
params,
|
|
28
|
+
repository: await getRepository(PDFTemplate),
|
|
29
|
+
searchables: ['name', 'description']
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const [items, total] = await queryBuilder.getManyAndCount()
|
|
33
|
+
|
|
34
|
+
return { items, total }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@FieldResolver(type => Domain)
|
|
38
|
+
async domain(@Root() pdfTemplate: PDFTemplate): Promise<Domain> {
|
|
39
|
+
return pdfTemplate.domainId && (await getRepository(Domain).findOneBy({ id: pdfTemplate.domainId }))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@FieldResolver(type => User)
|
|
43
|
+
async updater(@Root() pdfTemplate: PDFTemplate): Promise<User> {
|
|
44
|
+
return pdfTemplate.updaterId && (await getRepository(User).findOneBy({ id: pdfTemplate.updaterId }))
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@FieldResolver(type => User)
|
|
48
|
+
async creator(@Root() pdfTemplate: PDFTemplate): Promise<User> {
|
|
49
|
+
return pdfTemplate.creatorId && (await getRepository(User).findOneBy({ id: pdfTemplate.creatorId }))
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { ObjectType, Field, InputType, Int, ID } from 'type-graphql'
|
|
2
|
+
|
|
3
|
+
import { PDFTemplate, PDFTemplateStatus } from './pdf-template'
|
|
4
|
+
|
|
5
|
+
@InputType()
|
|
6
|
+
export class NewPDFTemplate {
|
|
7
|
+
@Field()
|
|
8
|
+
name: string
|
|
9
|
+
|
|
10
|
+
@Field({ nullable: true })
|
|
11
|
+
description?: string
|
|
12
|
+
|
|
13
|
+
@Field(type => PDFTemplateStatus, { nullable: true })
|
|
14
|
+
state?: PDFTemplateStatus
|
|
15
|
+
|
|
16
|
+
@Field({ nullable: true })
|
|
17
|
+
active?: boolean
|
|
18
|
+
|
|
19
|
+
@Field({ nullable: true })
|
|
20
|
+
content_template?: string
|
|
21
|
+
|
|
22
|
+
@Field({ nullable: true })
|
|
23
|
+
header_template?: string
|
|
24
|
+
|
|
25
|
+
@Field({ nullable: true })
|
|
26
|
+
footer_template?: string
|
|
27
|
+
|
|
28
|
+
@Field({ nullable: true })
|
|
29
|
+
cover_template?: string
|
|
30
|
+
|
|
31
|
+
@Field({ nullable: true })
|
|
32
|
+
last_template?: string
|
|
33
|
+
|
|
34
|
+
@Field({ nullable: true, defaultValue: 'A4' })
|
|
35
|
+
page_size: string
|
|
36
|
+
|
|
37
|
+
@Field({ nullable: true })
|
|
38
|
+
watermark: string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@InputType()
|
|
42
|
+
export class PDFTemplatePatch {
|
|
43
|
+
@Field(type => ID, { nullable: true })
|
|
44
|
+
id?: string
|
|
45
|
+
|
|
46
|
+
@Field({ nullable: true })
|
|
47
|
+
name?: string
|
|
48
|
+
|
|
49
|
+
@Field({ nullable: true })
|
|
50
|
+
description?: string
|
|
51
|
+
|
|
52
|
+
@Field(type => PDFTemplateStatus, { nullable: true })
|
|
53
|
+
state?: PDFTemplateStatus
|
|
54
|
+
|
|
55
|
+
@Field({ nullable: true })
|
|
56
|
+
active?: boolean
|
|
57
|
+
|
|
58
|
+
@Field({ nullable: true })
|
|
59
|
+
content_template?: string
|
|
60
|
+
|
|
61
|
+
@Field({ nullable: true })
|
|
62
|
+
header_template?: string
|
|
63
|
+
|
|
64
|
+
@Field({ nullable: true })
|
|
65
|
+
footer_template?: string
|
|
66
|
+
|
|
67
|
+
@Field({ nullable: true })
|
|
68
|
+
cover_template?: string
|
|
69
|
+
|
|
70
|
+
@Field({ nullable: true })
|
|
71
|
+
last_template?: string
|
|
72
|
+
|
|
73
|
+
@Field({ nullable: true, defaultValue: 'A4' })
|
|
74
|
+
page_size?: string
|
|
75
|
+
|
|
76
|
+
@Field({ nullable: true })
|
|
77
|
+
cuFlag?: string
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@ObjectType()
|
|
81
|
+
export class PDFTemplateList {
|
|
82
|
+
@Field(type => [PDFTemplate])
|
|
83
|
+
items: PDFTemplate[]
|
|
84
|
+
|
|
85
|
+
@Field(type => Int)
|
|
86
|
+
total: number
|
|
87
|
+
}
|