@things-factory/integration-pos 8.0.0-beta.0 → 8.0.0-beta.2
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/package.json +12 -12
- package/server/controllers/index.ts +0 -3
- package/server/controllers/pos-api/decorators.ts +0 -44
- package/server/controllers/pos-api/index.ts +0 -40
- package/server/controllers/xilnex/apis/get-outlet.ts +0 -14
- package/server/controllers/xilnex/apis/get-outlets.ts +0 -20
- package/server/controllers/xilnex/apis/index.ts +0 -1
- package/server/controllers/xilnex/index.ts +0 -8
- package/server/controllers/xilnex/platform-action.ts +0 -42
- package/server/controllers/xilnex/xilnex.ts +0 -123
- package/server/engine/connector/index.ts +0 -1
- package/server/engine/connector/pos-connector.ts +0 -33
- package/server/engine/index.ts +0 -2
- package/server/engine/task/index.ts +0 -1
- package/server/engine/task/pos-api.ts +0 -64
- package/server/entities/index.ts +0 -5
- package/server/entities/pos-store.ts +0 -76
- package/server/graphql/index.ts +0 -7
- package/server/graphql/resolvers/index.ts +0 -6
- package/server/graphql/resolvers/pos/create-pos-store.ts +0 -16
- package/server/graphql/resolvers/pos/delete-pos-store.ts +0 -20
- package/server/graphql/resolvers/pos/delete-pos-stores.ts +0 -25
- package/server/graphql/resolvers/pos/index.ts +0 -25
- package/server/graphql/resolvers/pos/pos-store.ts +0 -14
- package/server/graphql/resolvers/pos/pos-stores.ts +0 -15
- package/server/graphql/resolvers/pos/update-multiple-pos-stores.ts +0 -44
- package/server/graphql/resolvers/pos/update-pos-store.ts +0 -18
- package/server/graphql/resolvers/pos/xilnex/deactivate-xilnex-store.ts +0 -28
- package/server/graphql/resolvers/pos/xilnex/generate-xilnex-access-token.ts +0 -30
- package/server/graphql/resolvers/pos/xilnex/index.ts +0 -9
- package/server/graphql/resolvers/pos-api/index.ts +0 -8
- package/server/graphql/resolvers/pos-api/pos-outlet.ts +0 -24
- package/server/graphql/types/index.ts +0 -19
- package/server/graphql/types/pos/index.ts +0 -44
- package/server/graphql/types/pos/new-pos-store.ts +0 -11
- package/server/graphql/types/pos/pos-store-list.ts +0 -8
- package/server/graphql/types/pos/pos-store-patch.ts +0 -13
- package/server/graphql/types/pos/pos-store.ts +0 -20
- package/server/graphql/types/pos-api/pos-outlet.ts +0 -43
- package/server/index.ts +0 -9
- package/server/migrations/index.ts +0 -9
- package/server/routes.ts +0 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/integration-pos",
|
|
3
|
-
"version": "8.0.0-beta.
|
|
3
|
+
"version": "8.0.0-beta.2",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -26,16 +26,16 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@operato/data-grist": "^8.0.0-beta",
|
|
29
|
-
"@things-factory/apptool-ui": "^8.0.0-beta.
|
|
30
|
-
"@things-factory/auth-ui": "^8.0.0-beta.
|
|
31
|
-
"@things-factory/biz-base": "^8.0.0-beta.
|
|
32
|
-
"@things-factory/code-ui": "^8.0.0-beta.
|
|
33
|
-
"@things-factory/context-ui": "^8.0.0-beta.
|
|
34
|
-
"@things-factory/i18n-base": "^8.0.0-beta.
|
|
35
|
-
"@things-factory/integration-ui": "^8.0.0-beta.
|
|
36
|
-
"@things-factory/more-ui": "^8.0.0-beta.
|
|
37
|
-
"@things-factory/resource-ui": "^8.0.0-beta.
|
|
38
|
-
"@things-factory/setting-ui": "^8.0.0-beta.
|
|
29
|
+
"@things-factory/apptool-ui": "^8.0.0-beta.2",
|
|
30
|
+
"@things-factory/auth-ui": "^8.0.0-beta.2",
|
|
31
|
+
"@things-factory/biz-base": "^8.0.0-beta.2",
|
|
32
|
+
"@things-factory/code-ui": "^8.0.0-beta.2",
|
|
33
|
+
"@things-factory/context-ui": "^8.0.0-beta.2",
|
|
34
|
+
"@things-factory/i18n-base": "^8.0.0-beta.2",
|
|
35
|
+
"@things-factory/integration-ui": "^8.0.0-beta.2",
|
|
36
|
+
"@things-factory/more-ui": "^8.0.0-beta.2",
|
|
37
|
+
"@things-factory/resource-ui": "^8.0.0-beta.2",
|
|
38
|
+
"@things-factory/setting-ui": "^8.0.0-beta.2",
|
|
39
39
|
"debug": "^4.1.1",
|
|
40
40
|
"node-fetch": "^2.6.0"
|
|
41
41
|
},
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"nock": "^13.0.2",
|
|
50
50
|
"should": "^13.2.3"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "f03431a09435511b2595515658f9cb8f78ba4ebb"
|
|
53
53
|
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import Debug from 'debug'
|
|
2
|
-
const debug = Debug('things-factory:integration-pos:pos-api-decorator')
|
|
3
|
-
|
|
4
|
-
import { PosStore } from '../../entities'
|
|
5
|
-
|
|
6
|
-
const NOOP = v => v
|
|
7
|
-
|
|
8
|
-
export const api = (target: Object, property: string, descriptor: TypedPropertyDescriptor<any>): any => {
|
|
9
|
-
const method = descriptor.value
|
|
10
|
-
|
|
11
|
-
descriptor.value = async function (store: PosStore, request) {
|
|
12
|
-
const POSAPI = this
|
|
13
|
-
|
|
14
|
-
var { platform } = store
|
|
15
|
-
|
|
16
|
-
var { action: platformAction, apis } = POSAPI.getPlatform(platform)
|
|
17
|
-
|
|
18
|
-
var m = apis[method.name]
|
|
19
|
-
if (!m) {
|
|
20
|
-
throw Error(`POS Platform '${platform}' doesn't have API ${method.name}`)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
var {
|
|
24
|
-
path,
|
|
25
|
-
method: httpMethod = 'post',
|
|
26
|
-
denormalize = NOOP,
|
|
27
|
-
normalize = NOOP,
|
|
28
|
-
action = platformAction
|
|
29
|
-
} = m.apply(this, [request])
|
|
30
|
-
|
|
31
|
-
var denormalized = await denormalize(request || {}, { store })
|
|
32
|
-
debug('request', denormalized)
|
|
33
|
-
|
|
34
|
-
var response = await action.apply(this, [
|
|
35
|
-
{ store, method: httpMethod, path, request: denormalized, platformAction }
|
|
36
|
-
])
|
|
37
|
-
|
|
38
|
-
debug('response', response)
|
|
39
|
-
|
|
40
|
-
return await normalize(response, { store })
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return descriptor
|
|
44
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { getRepository } from '@things-factory/shell'
|
|
2
|
-
|
|
3
|
-
import { PosStore } from '../../entities'
|
|
4
|
-
import { api } from './decorators'
|
|
5
|
-
|
|
6
|
-
export const POS_STORE_STATUS = {
|
|
7
|
-
ACTIVE: 'active',
|
|
8
|
-
INACTIVE: 'inactive',
|
|
9
|
-
TERMINATED: 'terminated'
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export class POSAPI {
|
|
13
|
-
static platforms = {}
|
|
14
|
-
|
|
15
|
-
static registerPlatform(name, action, apis) {
|
|
16
|
-
POSAPI.platforms[name] = {
|
|
17
|
-
action,
|
|
18
|
-
apis
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
static getPlatform(name) {
|
|
23
|
-
return POSAPI.platforms[name]
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
static async getPosStore(id) {
|
|
27
|
-
const repository = getRepository(PosStore)
|
|
28
|
-
// return await repository.find(id)
|
|
29
|
-
return await repository.findOne({
|
|
30
|
-
where: { id },
|
|
31
|
-
relations: ['domain']
|
|
32
|
-
})
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
@api
|
|
36
|
-
static getOutlets(store, req): any {}
|
|
37
|
-
|
|
38
|
-
@api
|
|
39
|
-
static getOutlet(store, req): any {}
|
|
40
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const debug = require('debug')('things-factory:integration-pos:xilnex:get-outlets')
|
|
2
|
-
|
|
3
|
-
export function getOutlets() {
|
|
4
|
-
return {
|
|
5
|
-
method: 'get',
|
|
6
|
-
path: '/outlets',
|
|
7
|
-
denormalize(req) {
|
|
8
|
-
return {}
|
|
9
|
-
},
|
|
10
|
-
normalize(res) {
|
|
11
|
-
debug('response data', res)
|
|
12
|
-
const { outlets } = res
|
|
13
|
-
|
|
14
|
-
return {
|
|
15
|
-
items: outlets,
|
|
16
|
-
total: outlets.length
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './get-outlets'
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { Xilnex } from './xilnex'
|
|
2
|
-
|
|
3
|
-
import { config } from '@things-factory/env'
|
|
4
|
-
const xilnexConfig = config.get('posIntegrationXilnex', {})
|
|
5
|
-
const { apiKey, apiSecret } = xilnexConfig
|
|
6
|
-
|
|
7
|
-
function substitute(path, obj) {
|
|
8
|
-
var props = []
|
|
9
|
-
var re = /{([^}]+)}/g
|
|
10
|
-
var text
|
|
11
|
-
|
|
12
|
-
while ((text = re.exec(path))) {
|
|
13
|
-
props.push(text[1])
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
var result = path
|
|
17
|
-
props.forEach(prop => {
|
|
18
|
-
let value = obj[prop.trim()]
|
|
19
|
-
result = result.replace(`{${prop}}`, value === undefined ? '' : value)
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
return result
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const action = async ({ store, method = 'get', path, request }) => {
|
|
26
|
-
const client = new Xilnex({
|
|
27
|
-
store: store.storeId,
|
|
28
|
-
accessToken: store.accessToken,
|
|
29
|
-
storeId: store.storeId
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
const { resource = {}, payload = {} } = request
|
|
33
|
-
|
|
34
|
-
path = substitute(path, resource)
|
|
35
|
-
|
|
36
|
-
var response = await client[method](path, payload)
|
|
37
|
-
if (!response.ok) {
|
|
38
|
-
throw response.error
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return response.data
|
|
42
|
-
}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import fetch from 'node-fetch'
|
|
2
|
-
import Debug from 'debug'
|
|
3
|
-
|
|
4
|
-
const debug = Debug('things-factory:integration-pos:xilnex')
|
|
5
|
-
|
|
6
|
-
export type XilnexConfig = {
|
|
7
|
-
store: string
|
|
8
|
-
accessToken?: string,
|
|
9
|
-
storeId: string
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export class Xilnex {
|
|
13
|
-
private config: XilnexConfig
|
|
14
|
-
|
|
15
|
-
constructor(config: XilnexConfig) {
|
|
16
|
-
this.config = {
|
|
17
|
-
...config
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async get(path: string, data: any) {
|
|
22
|
-
const { store, accessToken, storeId: appid } = this.config
|
|
23
|
-
|
|
24
|
-
const qs = Object.entries(data)
|
|
25
|
-
.map(([k, v]) => `${k}=${encodeURIComponent(String(v))}`)
|
|
26
|
-
.join('&')
|
|
27
|
-
|
|
28
|
-
const endpoint = `https://api.xilnex.com/logic/v2${path}${qs ? '?' + qs : ''}`
|
|
29
|
-
debug('endpoint', endpoint)
|
|
30
|
-
|
|
31
|
-
const response = await fetch(endpoint, {
|
|
32
|
-
headers: {
|
|
33
|
-
'appid': appid,
|
|
34
|
-
'token': accessToken,
|
|
35
|
-
'auth': '5'
|
|
36
|
-
}
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
const result = await response.json()
|
|
40
|
-
debug('response result', result)
|
|
41
|
-
|
|
42
|
-
return result
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async post(path: string, data: any = {}) {
|
|
46
|
-
const { store, accessToken, storeId: appid } = this.config
|
|
47
|
-
|
|
48
|
-
debug('data', data)
|
|
49
|
-
|
|
50
|
-
const jsondata = JSON.stringify(data)
|
|
51
|
-
|
|
52
|
-
const endpoint = `https://api.xilnex.com/logic/v2${path}`
|
|
53
|
-
|
|
54
|
-
const response = await fetch(endpoint, {
|
|
55
|
-
method: 'post',
|
|
56
|
-
headers: {
|
|
57
|
-
'appid': appid,
|
|
58
|
-
'token': accessToken,
|
|
59
|
-
'auth': '5',
|
|
60
|
-
'Content-Type': 'application/json'
|
|
61
|
-
},
|
|
62
|
-
body: jsondata
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
const result = await response.json()
|
|
66
|
-
debug('response result', result)
|
|
67
|
-
|
|
68
|
-
return result
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
async put(path: string, data: any = {}) {
|
|
73
|
-
const { store, accessToken, storeId: appid } = this.config
|
|
74
|
-
|
|
75
|
-
debug('data', data)
|
|
76
|
-
|
|
77
|
-
const jsondata = JSON.stringify(data)
|
|
78
|
-
|
|
79
|
-
const endpoint = `https://api.xilnex.com/logic/v2${path}`
|
|
80
|
-
|
|
81
|
-
const response = await fetch(endpoint, {
|
|
82
|
-
method: 'put',
|
|
83
|
-
headers: {
|
|
84
|
-
'appid': appid,
|
|
85
|
-
'token': accessToken,
|
|
86
|
-
'auth': '5',
|
|
87
|
-
'Content-Type': 'application/json'
|
|
88
|
-
},
|
|
89
|
-
body: jsondata
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
const result = await response.json()
|
|
93
|
-
debug('response result', result)
|
|
94
|
-
|
|
95
|
-
return result
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
async delete(path: string, data: any = {}) {
|
|
99
|
-
const { store, accessToken, storeId: appid } = this.config
|
|
100
|
-
|
|
101
|
-
debug('data', data)
|
|
102
|
-
|
|
103
|
-
const jsondata = JSON.stringify(data)
|
|
104
|
-
|
|
105
|
-
const endpoint = `https://api.xilnex.com/logic/v2${path}`
|
|
106
|
-
|
|
107
|
-
const response = await fetch(endpoint, {
|
|
108
|
-
method: 'delete',
|
|
109
|
-
headers: {
|
|
110
|
-
'appid': appid,
|
|
111
|
-
'token': accessToken,
|
|
112
|
-
'auth': '5',
|
|
113
|
-
'Content-Type': 'application/json'
|
|
114
|
-
},
|
|
115
|
-
body: jsondata
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
const result = await response.json()
|
|
119
|
-
debug('response result', result)
|
|
120
|
-
|
|
121
|
-
return result
|
|
122
|
-
}
|
|
123
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import './pos-connector'
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { ConnectionManager, Connector, Connection } from '@things-factory/integration-base'
|
|
2
|
-
|
|
3
|
-
export class POSConnector implements Connector {
|
|
4
|
-
async ready(connectionConfigs) {
|
|
5
|
-
await Promise.all(connectionConfigs.map(this.connect))
|
|
6
|
-
|
|
7
|
-
ConnectionManager.logger.info('pos-connector connections are ready')
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
async connect(connection) {
|
|
11
|
-
const { domain, name, endpoint } = connection
|
|
12
|
-
|
|
13
|
-
ConnectionManager.addConnectionInstance(connection, { ...connection })
|
|
14
|
-
|
|
15
|
-
ConnectionManager.logger.info(`pos-connector connection(${name}:${connection.endpoint}) is connected`)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async disconnect(connection: Connection) {
|
|
19
|
-
ConnectionManager.removeConnectionInstance(connection)
|
|
20
|
-
|
|
21
|
-
ConnectionManager.logger.info(`pos-connector connection(${connection.name}) is disconnected`)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
get parameterSpec() {
|
|
25
|
-
return []
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
get taskPrefixes() {
|
|
29
|
-
return ['pos']
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
ConnectionManager.registerConnector('pos-connector', new POSConnector())
|
package/server/engine/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import './pos-api'
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { ConnectionManager, TaskRegistry } from '@things-factory/integration-base'
|
|
2
|
-
import { getRepository } from '@things-factory/shell'
|
|
3
|
-
import { access } from '@things-factory/utils'
|
|
4
|
-
|
|
5
|
-
import { POSAPI as API } from '../../controllers/pos-api'
|
|
6
|
-
import { PosStore } from '../../entities'
|
|
7
|
-
|
|
8
|
-
async function POSAPI(step, { logger, data, domain }) {
|
|
9
|
-
var {
|
|
10
|
-
connection,
|
|
11
|
-
params: { store: name, api, accessor }
|
|
12
|
-
} = step
|
|
13
|
-
|
|
14
|
-
var client = ConnectionManager.getConnectionInstanceByName(domain, connection) || {}
|
|
15
|
-
if (!client) {
|
|
16
|
-
throw new Error(`no connection : ${connection}`)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (!api) {
|
|
20
|
-
throw new Error(`no api defined`)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const repository = getRepository(PosStore)
|
|
24
|
-
const store: PosStore = await repository.findOne({
|
|
25
|
-
where: { domain: { id: domain.id }, name }
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
if (!store) {
|
|
29
|
-
throw new Error(`no store defined`)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
var result = await API[api](store, accessor ? access(accessor, data) : {})
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
data: result
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
POSAPI.parameterSpec = [
|
|
40
|
-
{
|
|
41
|
-
type: 'entity-selector',
|
|
42
|
-
name: 'store',
|
|
43
|
-
label: 'store',
|
|
44
|
-
property: {
|
|
45
|
-
queryName: 'stores',
|
|
46
|
-
valueKey: 'name'
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
type: 'select',
|
|
51
|
-
name: 'api',
|
|
52
|
-
label: 'api',
|
|
53
|
-
property: {
|
|
54
|
-
options: ['', 'getPOSInvoices']
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
type: 'string',
|
|
59
|
-
name: 'accessor',
|
|
60
|
-
label: 'accessor'
|
|
61
|
-
}
|
|
62
|
-
]
|
|
63
|
-
|
|
64
|
-
TaskRegistry.registerTaskHandler('pos-api', POSAPI)
|
package/server/entities/index.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { User } from '@things-factory/auth-base'
|
|
2
|
-
import { Domain } from '@things-factory/shell'
|
|
3
|
-
import { Column, CreateDateColumn, Entity, Index, ManyToOne, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm'
|
|
4
|
-
|
|
5
|
-
@Entity()
|
|
6
|
-
@Index(
|
|
7
|
-
'ix_pos-store_0',
|
|
8
|
-
(store: PosStore) => [store.domain, store.name], { unique: true }
|
|
9
|
-
)
|
|
10
|
-
export class PosStore {
|
|
11
|
-
@PrimaryGeneratedColumn('uuid')
|
|
12
|
-
id: string
|
|
13
|
-
|
|
14
|
-
@ManyToOne(type => Domain)
|
|
15
|
-
domain: Domain
|
|
16
|
-
|
|
17
|
-
@Column()
|
|
18
|
-
platform: string
|
|
19
|
-
|
|
20
|
-
@Column({
|
|
21
|
-
nullable: true
|
|
22
|
-
})
|
|
23
|
-
storeId: string
|
|
24
|
-
|
|
25
|
-
@Column()
|
|
26
|
-
countryCode: string
|
|
27
|
-
|
|
28
|
-
@Column({
|
|
29
|
-
nullable: true
|
|
30
|
-
})
|
|
31
|
-
status: string
|
|
32
|
-
|
|
33
|
-
@Column()
|
|
34
|
-
name: string
|
|
35
|
-
|
|
36
|
-
@Column({
|
|
37
|
-
nullable: true
|
|
38
|
-
})
|
|
39
|
-
accessInfo: string
|
|
40
|
-
|
|
41
|
-
@Column({
|
|
42
|
-
nullable: true
|
|
43
|
-
})
|
|
44
|
-
accessToken: string
|
|
45
|
-
|
|
46
|
-
@Column({
|
|
47
|
-
nullable: true
|
|
48
|
-
})
|
|
49
|
-
refreshToken: string
|
|
50
|
-
|
|
51
|
-
@Column({
|
|
52
|
-
nullable: true
|
|
53
|
-
})
|
|
54
|
-
store: string
|
|
55
|
-
|
|
56
|
-
@Column({
|
|
57
|
-
nullable: true
|
|
58
|
-
})
|
|
59
|
-
description: string
|
|
60
|
-
|
|
61
|
-
@CreateDateColumn()
|
|
62
|
-
createdAt: Date
|
|
63
|
-
|
|
64
|
-
@UpdateDateColumn()
|
|
65
|
-
updatedAt: Date
|
|
66
|
-
|
|
67
|
-
@ManyToOne(type => User, {
|
|
68
|
-
nullable: true
|
|
69
|
-
})
|
|
70
|
-
creator: User
|
|
71
|
-
|
|
72
|
-
@ManyToOne(type => User, {
|
|
73
|
-
nullable: true
|
|
74
|
-
})
|
|
75
|
-
updater: User
|
|
76
|
-
}
|
package/server/graphql/index.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { getRepository } from '@things-factory/shell'
|
|
2
|
-
|
|
3
|
-
import { POS_STORE_STATUS } from '../../../controllers'
|
|
4
|
-
import { PosStore } from '../../../entities'
|
|
5
|
-
|
|
6
|
-
export const createPosStore = {
|
|
7
|
-
async createPosStore(_: any, { store }, context: ResolverContext): Promise<PosStore> {
|
|
8
|
-
return await getRepository(PosStore).save({
|
|
9
|
-
status: POS_STORE_STATUS.INACTIVE,
|
|
10
|
-
...store,
|
|
11
|
-
domain: context.state.domain,
|
|
12
|
-
creator: context.state.user,
|
|
13
|
-
updater: context.state.user
|
|
14
|
-
})
|
|
15
|
-
}
|
|
16
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { getRepository } from '@things-factory/shell'
|
|
2
|
-
|
|
3
|
-
import { POS_STORE_STATUS } from '../../../controllers'
|
|
4
|
-
import { PosStore } from '../../../entities'
|
|
5
|
-
|
|
6
|
-
export const deletePosStore = {
|
|
7
|
-
async deletePosStore(_: any, { name }, context: ResolverContext) {
|
|
8
|
-
const foundStore: PosStore = await getRepository(PosStore).findOne({
|
|
9
|
-
where: { domain: { id: context.state.domain.id }, name }
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
await getRepository(PosStore).save({
|
|
13
|
-
...foundStore,
|
|
14
|
-
status: POS_STORE_STATUS.TERMINATED,
|
|
15
|
-
updater: context.state.user
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
return true
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { In } from 'typeorm'
|
|
2
|
-
|
|
3
|
-
import { getRepository } from '@things-factory/shell'
|
|
4
|
-
|
|
5
|
-
import { POS_STORE_STATUS } from '../../../controllers'
|
|
6
|
-
import { PosStore } from '../../../entities'
|
|
7
|
-
|
|
8
|
-
export const deletePosStores = {
|
|
9
|
-
async deletePosStores(_: any, { names }, context: ResolverContext) {
|
|
10
|
-
let foundStores: PosStore[] = await getRepository(PosStore).find({
|
|
11
|
-
where: { domain: { id: context.state.domain.id }, name: In(names) }
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
const updatedPosStore = foundStores.map((store: PosStore) => {
|
|
15
|
-
return {
|
|
16
|
-
...store,
|
|
17
|
-
status: POS_STORE_STATUS.TERMINATED,
|
|
18
|
-
updater: context.state.user
|
|
19
|
-
}
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
await getRepository(PosStore).save(updatedPosStore)
|
|
23
|
-
return true
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { posStoreResolver } from './pos-store'
|
|
2
|
-
import { posStoresResolver } from './pos-stores'
|
|
3
|
-
|
|
4
|
-
import { updateMultiplePosStore } from './update-multiple-pos-stores'
|
|
5
|
-
import { updatePosStore } from './update-pos-store'
|
|
6
|
-
import { createPosStore } from './create-pos-store'
|
|
7
|
-
import { deletePosStore } from './delete-pos-store'
|
|
8
|
-
import { deletePosStores } from './delete-pos-stores'
|
|
9
|
-
|
|
10
|
-
import * as Xilnex from './xilnex'
|
|
11
|
-
|
|
12
|
-
export const Query = {
|
|
13
|
-
...posStoresResolver,
|
|
14
|
-
...posStoreResolver,
|
|
15
|
-
...Xilnex.Query
|
|
16
|
-
} as any
|
|
17
|
-
|
|
18
|
-
export const Mutation = {
|
|
19
|
-
...updatePosStore,
|
|
20
|
-
...updateMultiplePosStore,
|
|
21
|
-
...createPosStore,
|
|
22
|
-
...deletePosStore,
|
|
23
|
-
...deletePosStores,
|
|
24
|
-
...Xilnex.Mutation
|
|
25
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { getRepository } from '@things-factory/shell'
|
|
2
|
-
|
|
3
|
-
import { PosStore } from '../../../entities'
|
|
4
|
-
|
|
5
|
-
export const posStoreResolver = {
|
|
6
|
-
async posStore(_: any, { id }, context: ResolverContext): Promise<PosStore> {
|
|
7
|
-
const repository = getRepository(PosStore)
|
|
8
|
-
|
|
9
|
-
return await getRepository(PosStore).findOne({
|
|
10
|
-
where: { domain: { id: context.state.domain.id }, id },
|
|
11
|
-
relations: ['domain', 'creator', 'updater']
|
|
12
|
-
})
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { convertListParams, getRepository, ListParam } from '@things-factory/shell'
|
|
2
|
-
|
|
3
|
-
import { PosStore } from '../../../entities'
|
|
4
|
-
|
|
5
|
-
export const posStoresResolver = {
|
|
6
|
-
async posStores(_: any, params: ListParam, context: ResolverContext): Promise<{ items: PosStore[]; total: number }> {
|
|
7
|
-
const { domain } = context.state
|
|
8
|
-
const convertedParams = convertListParams(params, { domain })
|
|
9
|
-
const [items, total] = await getRepository(PosStore).findAndCount({
|
|
10
|
-
...convertedParams,
|
|
11
|
-
relations: ['domain', 'creator', 'updater']
|
|
12
|
-
})
|
|
13
|
-
return { items, total }
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { getRepository } from '@things-factory/shell'
|
|
2
|
-
|
|
3
|
-
import { PosStore } from '../../../entities'
|
|
4
|
-
|
|
5
|
-
export const updateMultiplePosStore = {
|
|
6
|
-
async updateMultiplePosStore(_: any, { patches }, context: ResolverContext) {
|
|
7
|
-
let results = []
|
|
8
|
-
const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
|
|
9
|
-
const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
|
|
10
|
-
const posStoreRepo = getRepository(PosStore)
|
|
11
|
-
|
|
12
|
-
if (_createRecords.length > 0) {
|
|
13
|
-
for (let i = 0; i < _createRecords.length; i++) {
|
|
14
|
-
const newRecord = _createRecords[i]
|
|
15
|
-
|
|
16
|
-
const result = await posStoreRepo.save({
|
|
17
|
-
...newRecord,
|
|
18
|
-
domain: context.state.domain,
|
|
19
|
-
creator: context.state.user,
|
|
20
|
-
updater: context.state.user
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
results.push({ ...result, cuFlag: '+' })
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (_updateRecords.length > 0) {
|
|
28
|
-
for (let i = 0; i < _updateRecords.length; i++) {
|
|
29
|
-
const newRecord = _updateRecords[i]
|
|
30
|
-
const store: PosStore = await posStoreRepo.findOneBy({ id: newRecord.id })
|
|
31
|
-
|
|
32
|
-
const result = await posStoreRepo.save({
|
|
33
|
-
...store,
|
|
34
|
-
...newRecord,
|
|
35
|
-
updater: context.state.user
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
results.push({ ...result, cuFlag: 'M' })
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return results
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { getRepository } from '@things-factory/shell'
|
|
2
|
-
|
|
3
|
-
import { PosStore } from '../../../entities'
|
|
4
|
-
|
|
5
|
-
export const updatePosStore = {
|
|
6
|
-
async updatePosStore(_: any, { name, patch }, context: ResolverContext) {
|
|
7
|
-
const repository = getRepository(PosStore)
|
|
8
|
-
const store: any = await repository.findOne({
|
|
9
|
-
where: { domain: { id: context.state.domain.id }, name }
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
return await repository.save({
|
|
13
|
-
...store,
|
|
14
|
-
...patch,
|
|
15
|
-
updater: context.state.user
|
|
16
|
-
})
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { getRepository } from '@things-factory/shell'
|
|
2
|
-
|
|
3
|
-
import { POS_STORE_STATUS } from '../../../../controllers'
|
|
4
|
-
import { PosStore } from '../../../../entities'
|
|
5
|
-
|
|
6
|
-
export const deactivateXilnexPosStore = {
|
|
7
|
-
async deactivateXilnexPosStore(_: any, { id }, context: ResolverContext) {
|
|
8
|
-
const repository = getRepository(PosStore)
|
|
9
|
-
const store: any = await repository.findOne({
|
|
10
|
-
where: { domain: { id: context.state.domain.id }, id }
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
var patch = {
|
|
14
|
-
storeId: '',
|
|
15
|
-
accessToken: '',
|
|
16
|
-
refreshToken: '',
|
|
17
|
-
accessInfo: '',
|
|
18
|
-
countryCode: '',
|
|
19
|
-
status: POS_STORE_STATUS.INACTIVE
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return await repository.save({
|
|
23
|
-
...store,
|
|
24
|
-
...patch,
|
|
25
|
-
updater: context.state.user
|
|
26
|
-
})
|
|
27
|
-
}
|
|
28
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { config } from '@things-factory/env'
|
|
2
|
-
import { getRepository } from '@things-factory/shell'
|
|
3
|
-
|
|
4
|
-
import { POS_STORE_STATUS } from '../../../../controllers'
|
|
5
|
-
import { PosStore } from '../../../../entities'
|
|
6
|
-
|
|
7
|
-
const xilnexConfig = config.get('posIntegrationXilnex', {})
|
|
8
|
-
const { apiKey, apiSecret } = xilnexConfig
|
|
9
|
-
|
|
10
|
-
export const generateXilnexAccessToken = {
|
|
11
|
-
async generateXilnexAccessToken(_: any, { id, appid, token }, context: ResolverContext) {
|
|
12
|
-
const repository = getRepository(PosStore)
|
|
13
|
-
const store: any = await repository.findOne({
|
|
14
|
-
where: { domain: { id: context.state.domain.id }, id }
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
var patch = {
|
|
18
|
-
accessToken: token,
|
|
19
|
-
refreshToken: '',
|
|
20
|
-
storeId: appid,
|
|
21
|
-
status: POS_STORE_STATUS.ACTIVE
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return await repository.save({
|
|
25
|
-
...store,
|
|
26
|
-
...patch,
|
|
27
|
-
updater: context.state.user
|
|
28
|
-
})
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { deactivateXilnexPosStore } from './deactivate-xilnex-store'
|
|
2
|
-
import { generateXilnexAccessToken } from './generate-xilnex-access-token'
|
|
3
|
-
|
|
4
|
-
export const Query = {}
|
|
5
|
-
|
|
6
|
-
export const Mutation = {
|
|
7
|
-
...generateXilnexAccessToken,
|
|
8
|
-
...deactivateXilnexPosStore
|
|
9
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { POSAPI } from '../../../controllers/pos-api'
|
|
2
|
-
|
|
3
|
-
export const queryPosOutlet = {
|
|
4
|
-
async getPosOutlets(_: any, { posId, params: ListParam }, context: ResolverContext) {
|
|
5
|
-
var pos = await POSAPI.getPosStore(posId)
|
|
6
|
-
|
|
7
|
-
return await POSAPI.getOutlets(pos, {
|
|
8
|
-
pagination: {
|
|
9
|
-
page: 0,
|
|
10
|
-
limit: 100
|
|
11
|
-
}
|
|
12
|
-
})
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
async getPosOutlet(_: any, { posId, outletNo }, context: ResolverContext) {
|
|
16
|
-
var pos = await POSAPI.getPosStore(posId)
|
|
17
|
-
|
|
18
|
-
return await POSAPI.getOutlet(pos, {
|
|
19
|
-
outletNo
|
|
20
|
-
})
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const mutatePosOutlet = {}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import * as POS from './pos'
|
|
2
|
-
import * as Outlet from './pos-api/pos-outlet'
|
|
3
|
-
|
|
4
|
-
export const queries = [
|
|
5
|
-
POS.Query,
|
|
6
|
-
Outlet.Query
|
|
7
|
-
]
|
|
8
|
-
|
|
9
|
-
export const mutations = [
|
|
10
|
-
POS.Mutation,
|
|
11
|
-
Outlet.Mutation
|
|
12
|
-
]
|
|
13
|
-
|
|
14
|
-
export const subscriptions = []
|
|
15
|
-
|
|
16
|
-
export const types = [
|
|
17
|
-
...POS.Types,
|
|
18
|
-
...Outlet.Types
|
|
19
|
-
]
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { PosStore } from './pos-store'
|
|
2
|
-
import { NewPosStore } from './new-pos-store'
|
|
3
|
-
import { PosStorePatch } from './pos-store-patch'
|
|
4
|
-
import { PosStoreList } from './pos-store-list'
|
|
5
|
-
|
|
6
|
-
export const Mutation = `
|
|
7
|
-
createPosStore (
|
|
8
|
-
store: NewPosStore!
|
|
9
|
-
): PosStore
|
|
10
|
-
|
|
11
|
-
updatePosStore (
|
|
12
|
-
name: String!
|
|
13
|
-
patch: PosStorePatch!
|
|
14
|
-
): PosStore
|
|
15
|
-
|
|
16
|
-
updateMultiplePosStore (
|
|
17
|
-
patches: [PosStorePatch]!
|
|
18
|
-
): [PosStore]
|
|
19
|
-
|
|
20
|
-
deletePosStore (
|
|
21
|
-
name: String!
|
|
22
|
-
): Boolean
|
|
23
|
-
|
|
24
|
-
deletePosStores (
|
|
25
|
-
names: [String]!
|
|
26
|
-
): Boolean
|
|
27
|
-
|
|
28
|
-
generateXilnexAccessToken (
|
|
29
|
-
id: String!
|
|
30
|
-
appid: String!
|
|
31
|
-
token: String!
|
|
32
|
-
): PosStore
|
|
33
|
-
|
|
34
|
-
deactivateXilnexPosStore (
|
|
35
|
-
name: String!
|
|
36
|
-
): PosStore
|
|
37
|
-
`
|
|
38
|
-
|
|
39
|
-
export const Query = `
|
|
40
|
-
posStores(filters: [Filter], pagination: Pagination, sortings: [Sorting]): PosStoreList
|
|
41
|
-
posStore(id: String!): PosStore
|
|
42
|
-
`
|
|
43
|
-
|
|
44
|
-
export const Types = [PosStore, NewPosStore, PosStorePatch, PosStoreList]
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import gql from 'graphql-tag'
|
|
2
|
-
|
|
3
|
-
export const PosStore = gql`
|
|
4
|
-
type PosStore {
|
|
5
|
-
id: String
|
|
6
|
-
name: String
|
|
7
|
-
domain: Domain
|
|
8
|
-
description: String
|
|
9
|
-
platform: String
|
|
10
|
-
storeId: String
|
|
11
|
-
countryCode: String
|
|
12
|
-
status: String
|
|
13
|
-
accessToken: String
|
|
14
|
-
accessInfo: String
|
|
15
|
-
updater: User
|
|
16
|
-
creator: User
|
|
17
|
-
updatedAt: String
|
|
18
|
-
createdAt: String
|
|
19
|
-
}
|
|
20
|
-
`
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import gql from 'graphql-tag'
|
|
2
|
-
|
|
3
|
-
const PosOutletList = gql`
|
|
4
|
-
type PosOutletList {
|
|
5
|
-
items: [PosOutlet]
|
|
6
|
-
total: Int
|
|
7
|
-
}
|
|
8
|
-
`
|
|
9
|
-
|
|
10
|
-
const PosOutletPatch = gql`
|
|
11
|
-
input PosOutletPatch {
|
|
12
|
-
id: String!
|
|
13
|
-
name: String
|
|
14
|
-
description: String
|
|
15
|
-
cuFlag: String
|
|
16
|
-
}
|
|
17
|
-
`
|
|
18
|
-
|
|
19
|
-
const PosOutlet = gql`
|
|
20
|
-
type PosOutlet {
|
|
21
|
-
id: String
|
|
22
|
-
name: String
|
|
23
|
-
}
|
|
24
|
-
`
|
|
25
|
-
|
|
26
|
-
export const Mutation = `
|
|
27
|
-
`
|
|
28
|
-
|
|
29
|
-
export const Query = `
|
|
30
|
-
getPosOutlets(
|
|
31
|
-
posId: String!
|
|
32
|
-
filters: [Filter]
|
|
33
|
-
pagination: Pagination
|
|
34
|
-
sortings: [Sorting]
|
|
35
|
-
): PosOutletList
|
|
36
|
-
|
|
37
|
-
getPosOutlet(
|
|
38
|
-
posId: String!
|
|
39
|
-
outletNo: String!
|
|
40
|
-
): PosOutlet
|
|
41
|
-
`
|
|
42
|
-
|
|
43
|
-
export const Types = [PosOutlet, PosOutletPatch, PosOutletList]
|
package/server/index.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
const glob = require('glob')
|
|
2
|
-
const path = require('path')
|
|
3
|
-
|
|
4
|
-
export var migrations = []
|
|
5
|
-
|
|
6
|
-
glob.sync(path.resolve(__dirname, '.', '**', '*.js')).forEach(function(file) {
|
|
7
|
-
if (file.indexOf('index.js') !== -1) return
|
|
8
|
-
migrations = migrations.concat(Object.values(require(path.resolve(file))) || [])
|
|
9
|
-
})
|