@things-factory/integration-powrup 4.3.238

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.
Files changed (80) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/client/actions/main.js +1 -0
  3. package/client/bootstrap.js +8 -0
  4. package/client/index.js +1 -0
  5. package/client/pages/main.js +25 -0
  6. package/client/reducers/main.js +17 -0
  7. package/client/route.js +7 -0
  8. package/dist-server/controllers/index.js +20 -0
  9. package/dist-server/controllers/index.js.map +1 -0
  10. package/dist-server/controllers/powrup/apis/echo.js +19 -0
  11. package/dist-server/controllers/powrup/apis/echo.js.map +1 -0
  12. package/dist-server/controllers/powrup/apis/fetch-document.js +24 -0
  13. package/dist-server/controllers/powrup/apis/fetch-document.js.map +1 -0
  14. package/dist-server/controllers/powrup/apis/index.js +20 -0
  15. package/dist-server/controllers/powrup/apis/index.js.map +1 -0
  16. package/dist-server/controllers/powrup/apis/initiate-shipment.js +23 -0
  17. package/dist-server/controllers/powrup/apis/initiate-shipment.js.map +1 -0
  18. package/dist-server/controllers/powrup/apis/pack-order.js +34 -0
  19. package/dist-server/controllers/powrup/apis/pack-order.js.map +1 -0
  20. package/dist-server/controllers/powrup/apis/update-stock.js +34 -0
  21. package/dist-server/controllers/powrup/apis/update-stock.js.map +1 -0
  22. package/dist-server/controllers/powrup/index.js +34 -0
  23. package/dist-server/controllers/powrup/index.js.map +1 -0
  24. package/dist-server/controllers/powrup/platform-action.js +30 -0
  25. package/dist-server/controllers/powrup/platform-action.js.map +1 -0
  26. package/dist-server/controllers/powrup/powrup.js +62 -0
  27. package/dist-server/controllers/powrup/powrup.js.map +1 -0
  28. package/dist-server/controllers/powrup-api/decorators.js +40 -0
  29. package/dist-server/controllers/powrup-api/decorators.js.map +1 -0
  30. package/dist-server/controllers/powrup-api/index.js +71 -0
  31. package/dist-server/controllers/powrup-api/index.js.map +1 -0
  32. package/dist-server/index.js +22 -0
  33. package/dist-server/index.js.map +1 -0
  34. package/dist-server/middlewares/index.js +8 -0
  35. package/dist-server/middlewares/index.js.map +1 -0
  36. package/dist-server/migrations/index.js +12 -0
  37. package/dist-server/migrations/index.js.map +1 -0
  38. package/dist-server/routes.js +25 -0
  39. package/dist-server/routes.js.map +1 -0
  40. package/dist-server/service/index.js +32 -0
  41. package/dist-server/service/index.js.map +1 -0
  42. package/dist-server/service/powrup/index.js +9 -0
  43. package/dist-server/service/powrup/index.js.map +1 -0
  44. package/dist-server/service/powrup/powrup-mutation.js +120 -0
  45. package/dist-server/service/powrup/powrup-mutation.js.map +1 -0
  46. package/dist-server/service/powrup/powrup-query.js +87 -0
  47. package/dist-server/service/powrup/powrup-query.js.map +1 -0
  48. package/dist-server/service/powrup/powrup-type.js +97 -0
  49. package/dist-server/service/powrup/powrup-type.js.map +1 -0
  50. package/dist-server/service/powrup/powrup.js +132 -0
  51. package/dist-server/service/powrup/powrup.js.map +1 -0
  52. package/package.json +54 -0
  53. package/server/controllers/index.ts +4 -0
  54. package/server/controllers/powrup/apis/echo.ts +14 -0
  55. package/server/controllers/powrup/apis/fetch-document.ts +21 -0
  56. package/server/controllers/powrup/apis/index.ts +3 -0
  57. package/server/controllers/powrup/apis/initiate-shipment.ts +19 -0
  58. package/server/controllers/powrup/apis/pack-order.ts +32 -0
  59. package/server/controllers/powrup/apis/update-stock.ts +30 -0
  60. package/server/controllers/powrup/index.ts +7 -0
  61. package/server/controllers/powrup/platform-action.ts +34 -0
  62. package/server/controllers/powrup/powrup.ts +74 -0
  63. package/server/controllers/powrup-api/decorators.ts +54 -0
  64. package/server/controllers/powrup-api/index.ts +42 -0
  65. package/server/index.ts +6 -0
  66. package/server/middlewares/index.ts +3 -0
  67. package/server/migrations/index.ts +9 -0
  68. package/server/routes.ts +28 -0
  69. package/server/service/index.ts +18 -0
  70. package/server/service/powrup/index.ts +6 -0
  71. package/server/service/powrup/powrup-mutation.ts +112 -0
  72. package/server/service/powrup/powrup-query.ts +43 -0
  73. package/server/service/powrup/powrup-type.ts +60 -0
  74. package/server/service/powrup/powrup.ts +113 -0
  75. package/things-factory.config.js +13 -0
  76. package/translations/en.json +1 -0
  77. package/translations/ko.json +1 -0
  78. package/translations/ms.json +1 -0
  79. package/translations/zh.json +1 -0
  80. package/tsconfig.json +9 -0
@@ -0,0 +1,32 @@
1
+ export function packOrder() {
2
+ return {
3
+ method: 'post',
4
+ path: '/order-pack',
5
+ denormalize(req) {
6
+ const { refOrderId } = req
7
+
8
+ return {
9
+ payload: {
10
+ orderId: refOrderId
11
+ }
12
+ }
13
+ },
14
+ normalize(res) {
15
+ const { orderId, packages } = res.resultObject
16
+
17
+ const orderPackages: any[] = packages.map(pkg => {
18
+ return {
19
+ packageId: pkg.packageId,
20
+ items: pkg.items.map(item => {
21
+ return {
22
+ refCode: item.universalIdentifier,
23
+ qty: item.quantity
24
+ }
25
+ })
26
+ }
27
+ })
28
+
29
+ return { orderId, packages: orderPackages }
30
+ }
31
+ }
32
+ }
@@ -0,0 +1,30 @@
1
+ export function updateStock() {
2
+ return {
3
+ method: 'post',
4
+ path: '/product/stock-update',
5
+ denormalize(req) {
6
+ const { warehouseDomainId, powrupInvs } = req
7
+
8
+ return {
9
+ payload: {
10
+ channelId: warehouseDomainId,
11
+ products: powrupInvs.map(pi => {
12
+ return {
13
+ universalIdentifier: pi.refCode,
14
+ stock: pi.stock.map(st => {
15
+ return {
16
+ quantityTotal: st.quantityTotal,
17
+ quantityReserved: st.quantityReserved,
18
+ quantityBuffer: st.quantityBuffer
19
+ }
20
+ })
21
+ }
22
+ })
23
+ }
24
+ }
25
+ },
26
+ normalize(res) {
27
+ return res
28
+ }
29
+ }
30
+ }
@@ -0,0 +1,7 @@
1
+ import { PowrupAPI } from '../powrup-api'
2
+ import * as APIS from './apis'
3
+ import { action } from './platform-action'
4
+
5
+ export * from './powrup'
6
+
7
+ PowrupAPI.registerPlatform('powrup', action, APIS)
@@ -0,0 +1,34 @@
1
+ import { Powrup } from './powrup'
2
+
3
+ function substitute(path, obj) {
4
+ var props = []
5
+ var re = /{([^}]+)}/g
6
+ var text
7
+
8
+ while ((text = re.exec(path))) {
9
+ props.push(text[1])
10
+ }
11
+
12
+ var result = path
13
+ props.forEach(prop => {
14
+ let value = obj[prop.trim()]
15
+ result = result.replace(`{${prop}}`, value === undefined ? '' : value)
16
+ })
17
+
18
+ return result
19
+ }
20
+
21
+ export const action = async ({ integration, method = 'get', path, request }) => {
22
+ const client = new Powrup({ apiKey: integration.accountId, staging: integration.staging })
23
+
24
+ const { resource = {}, payload = {} } = request
25
+
26
+ path = substitute(path, resource)
27
+
28
+ var response = await client[method](path, payload)
29
+ if (response.errors) {
30
+ throw response
31
+ }
32
+
33
+ return response
34
+ }
@@ -0,0 +1,74 @@
1
+ import fetch from 'node-fetch'
2
+
3
+ const debug = require('debug')('things-factory:integration-powrup:powrup')
4
+
5
+ export type PowrupConfig = {
6
+ apiKey: string
7
+ staging?: boolean
8
+ }
9
+
10
+ export class Powrup {
11
+ private config: PowrupConfig
12
+
13
+ constructor(config: PowrupConfig) {
14
+ this.config = {
15
+ ...config
16
+ }
17
+ }
18
+
19
+ getBaseUrl() {
20
+ return `https://api${this.config.staging ? '-test' : ''}.powrup.asia`
21
+ }
22
+
23
+ async post(path: string, data: any = {}) {
24
+ const { apiKey } = this.config
25
+
26
+ debug('data', data)
27
+
28
+ const jsondata = JSON.stringify(data)
29
+ const fullPath: string = `${this.getBaseUrl()}${path}`
30
+
31
+ const response: any = await fetch(fullPath, {
32
+ method: 'post',
33
+ headers: {
34
+ 'Content-Type': 'application/json',
35
+ 'X-Authorization': apiKey
36
+ },
37
+ body: jsondata
38
+ })
39
+
40
+ if (response.ok) {
41
+ return await response.json()
42
+ } else {
43
+ const result = await response.text()
44
+ throw new Error(`(${response.status}) ${result}`)
45
+ }
46
+ }
47
+
48
+ async get(path: string, data: any = {}) {
49
+ const { apiKey } = this.config
50
+
51
+ const qs = Object.entries(data)
52
+ .map(([k, v]) => `${k}=${encodeURIComponent(String(v))}`)
53
+ .join('&')
54
+
55
+ const fullPath: string = `${this.getBaseUrl()}${path}`
56
+ const endpoint = `${fullPath}${qs ? '?' + qs : ''}`
57
+ debug('endpoint', endpoint)
58
+
59
+ const response: any = await fetch(endpoint, {
60
+ method: 'get',
61
+ headers: {
62
+ 'Content-Type': 'application/json',
63
+ 'X-Authorization': apiKey
64
+ }
65
+ })
66
+
67
+ if (response.ok) {
68
+ return await response.json()
69
+ } else {
70
+ const result = await response.text()
71
+ throw new Error(`(${response.status}) ${result}`)
72
+ }
73
+ }
74
+ }
@@ -0,0 +1,54 @@
1
+ import Debug from 'debug'
2
+
3
+ import { createPayloadLog } from '@things-factory/integration-base'
4
+
5
+ import { Powrup } from '../../service'
6
+
7
+ const debug = Debug('things-factory:integration-powrup:powrup-api-decorator')
8
+
9
+ const NOOP = v => v
10
+
11
+ export const api = (target: Object, property: string, descriptor: TypedPropertyDescriptor<any>): any => {
12
+ const method = descriptor.value
13
+
14
+ descriptor.value = async function (powrup: Powrup, request) {
15
+ const PowrupAPI = this
16
+
17
+ var { platform } = powrup
18
+
19
+ var { action: platformAction, apis } = PowrupAPI.getPlatform(platform)
20
+
21
+ var m = apis[method.name]
22
+ if (!m) {
23
+ throw Error(`${platform} doesn't have API ${method.name}`)
24
+ }
25
+
26
+ var {
27
+ path,
28
+ method: httpMethod = 'post',
29
+ denormalize = NOOP,
30
+ normalize = NOOP,
31
+ action = platformAction
32
+ } = m.apply(this, [request])
33
+
34
+ var denormalized = await denormalize(request || {}, { powrup })
35
+ debug('request', denormalized)
36
+
37
+ try {
38
+ var response = await action.apply(this, [
39
+ { powrup, method: httpMethod, path, request: denormalized, platformAction }
40
+ ])
41
+
42
+ createPayloadLog(powrup.id, path, denormalized, response, request?.context)
43
+
44
+ debug('response', response)
45
+
46
+ return await normalize(response, { powrup })
47
+ } catch (error) {
48
+ createPayloadLog(powrup.id, path, denormalized, error?.message, request?.context)
49
+ throw error
50
+ }
51
+ }
52
+
53
+ return descriptor
54
+ }
@@ -0,0 +1,42 @@
1
+ import { getRepository } from 'typeorm'
2
+
3
+ import { Powrup } from '../../service'
4
+ import { api } from './decorators'
5
+
6
+ export class PowrupAPI {
7
+ static platforms = {}
8
+
9
+ static registerPlatform(name, action, apis) {
10
+ PowrupAPI.platforms[name] = {
11
+ action,
12
+ apis
13
+ }
14
+ }
15
+
16
+ static getPlatform(name) {
17
+ return PowrupAPI.platforms[name]
18
+ }
19
+
20
+ static async getPowrup(id) {
21
+ const repository = getRepository(Powrup)
22
+ return await repository.findOne({
23
+ where: { id },
24
+ relations: ['domain']
25
+ })
26
+ }
27
+
28
+ @api
29
+ static echo(powrup, req): any {}
30
+
31
+ @api
32
+ static fetchDocument(powrup, req): any {}
33
+
34
+ @api
35
+ static initiateShipment(powrup, req): any {}
36
+
37
+ @api
38
+ static packOrder(powrup, req): any {}
39
+
40
+ @api
41
+ static updateStock(powrup, req): any {}
42
+ }
@@ -0,0 +1,6 @@
1
+ import './routes'
2
+
3
+ export * from './migrations'
4
+ export * from './middlewares'
5
+ export * from './controllers'
6
+ export * from './service'
@@ -0,0 +1,3 @@
1
+ export function initMiddlewares(app) {
2
+ /* can add middlewares into app */
3
+ }
@@ -0,0 +1,9 @@
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
+ })
@@ -0,0 +1,28 @@
1
+ const debug = require('debug')('things-factory:integration-powrup:routes')
2
+
3
+ process.on('bootstrap-module-global-public-route' as any, (app, globalPublicRouter) => {
4
+ /*
5
+ * can add global public routes to application (auth not required, tenancy not required)
6
+ *
7
+ * ex) routes.get('/path', async(context, next) => {})
8
+ * ex) routes.post('/path', async(context, next) => {})
9
+ */
10
+ })
11
+
12
+ process.on('bootstrap-module-global-private-route' as any, (app, globalPrivateRouter) => {
13
+ /*
14
+ * can add global private routes to application (auth required, tenancy not required)
15
+ */
16
+ })
17
+
18
+ process.on('bootstrap-module-domain-public-route' as any, (app, domainPublicRouter) => {
19
+ /*
20
+ * can add domain public routes to application (auth not required, tenancy required)
21
+ */
22
+ })
23
+
24
+ process.on('bootstrap-module-domain-private-route' as any, (app, domainPrivateRouter) => {
25
+ /*
26
+ * can add domain private routes to application (auth required, tenancy required)
27
+ */
28
+ })
@@ -0,0 +1,18 @@
1
+ /* EXPORT ENTITY TYPES */
2
+ export * from './powrup/powrup'
3
+
4
+ /* IMPORT ENTITIES AND RESOLVERS */
5
+ import { entities as PowrupEntities, resolvers as PowrupResolvers } from './powrup'
6
+
7
+ export const entities = [
8
+ /* ENTITIES */
9
+ ...PowrupEntities,
10
+ ]
11
+
12
+
13
+ export const schema = {
14
+ resolverClasses: [
15
+ /* RESOLVER CLASSES */
16
+ ...PowrupResolvers,
17
+ ]
18
+ }
@@ -0,0 +1,6 @@
1
+ import { Powrup } from './powrup'
2
+ import { PowrupQuery } from './powrup-query'
3
+ import { PowrupMutation } from './powrup-mutation'
4
+
5
+ export const entities = [Powrup]
6
+ export const resolvers = [PowrupQuery, PowrupMutation]
@@ -0,0 +1,112 @@
1
+ import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'
2
+ import { getRepository, In } from 'typeorm'
3
+ import { Powrup } from './powrup'
4
+ import { NewPowrup, PowrupPatch } from './powrup-type'
5
+
6
+ @Resolver(Powrup)
7
+ export class PowrupMutation {
8
+ @Directive('@transaction')
9
+ @Mutation(returns => Powrup, { description: 'To create new Powrup' })
10
+ async createPowrup(@Arg('powrup') powrup: NewPowrup, @Ctx() context: any): Promise<Powrup> {
11
+ const { domain, user, tx } = context.state
12
+
13
+ return await tx.getRepository(Powrup).save({
14
+ ...powrup,
15
+ domain,
16
+ creator: user,
17
+ updater: user
18
+ })
19
+ }
20
+
21
+ @Directive('@transaction')
22
+ @Mutation(returns => Powrup, { description: 'To modify Powrup information' })
23
+ async updatePowrup(
24
+ @Arg('id') id: string,
25
+ @Arg('patch') patch: PowrupPatch,
26
+ @Ctx() context: any
27
+ ): Promise<Powrup> {
28
+ const { domain, user, tx } = context.state
29
+
30
+ const repository = tx.getRepository(Powrup)
31
+ const powrup = await repository.findOne({
32
+ where: { domain, id }
33
+ })
34
+
35
+ return await repository.save({
36
+ ...powrup,
37
+ ...patch,
38
+ updater: user
39
+ })
40
+ }
41
+
42
+ @Directive('@transaction')
43
+ @Mutation(returns => [Powrup], { description: "To modify multiple Powrups' information" })
44
+ async updateMultiplePowrup(
45
+ @Arg('patches', type => [PowrupPatch]) patches: PowrupPatch[],
46
+ @Ctx() context: any
47
+ ): Promise<Powrup[]> {
48
+ const { domain, user, tx } = context.state
49
+
50
+ let results = []
51
+ const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
52
+ const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
53
+ const powrupRepo = tx.getRepository(Powrup)
54
+
55
+ if (_createRecords.length > 0) {
56
+ for (let i = 0; i < _createRecords.length; i++) {
57
+ const newRecord = _createRecords[i]
58
+
59
+ const result = await powrupRepo.save({
60
+ ...newRecord,
61
+ domain,
62
+ creator: user,
63
+ updater: user
64
+ })
65
+
66
+ results.push({ ...result, cuFlag: '+' })
67
+ }
68
+ }
69
+
70
+ if (_updateRecords.length > 0) {
71
+ for (let i = 0; i < _updateRecords.length; i++) {
72
+ const newRecord = _updateRecords[i]
73
+ const powrup = await powrupRepo.findOne(newRecord.id)
74
+
75
+ const result = await powrupRepo.save({
76
+ ...powrup,
77
+ ...newRecord,
78
+ updater: user
79
+ })
80
+
81
+ results.push({ ...result, cuFlag: 'M' })
82
+ }
83
+ }
84
+
85
+ return results
86
+ }
87
+
88
+ @Directive('@transaction')
89
+ @Mutation(returns => Boolean, { description: 'To delete Powrup' })
90
+ async deletePowrup(@Arg('id') id: string, @Ctx() context: any): Promise<boolean> {
91
+ const { domain, tx } = context.state
92
+
93
+ await tx.getRepository(Powrup).delete({ domain, id })
94
+ return true
95
+ }
96
+
97
+ @Directive('@transaction')
98
+ @Mutation(returns => Boolean, { description: 'To delete multiple powrups' })
99
+ async deletePowrups(
100
+ @Arg('ids', type => [String]) ids: string[],
101
+ @Ctx() context: any
102
+ ): Promise<boolean> {
103
+ const { domain, tx } = context.state
104
+
105
+ await tx.getRepository(Powrup).delete({
106
+ domain,
107
+ id: In(ids)
108
+ })
109
+
110
+ return true
111
+ }
112
+ }
@@ -0,0 +1,43 @@
1
+ import { Resolver, Query, FieldResolver, Root, Args, Arg, Ctx, Directive } from 'type-graphql'
2
+ import { getRepository } from 'typeorm'
3
+ import { Domain, ListParam, convertListParams } from '@things-factory/shell'
4
+ import { User } from '@things-factory/auth-base'
5
+ import { Powrup } from './powrup'
6
+ import { PowrupList } from './powrup-type'
7
+
8
+ @Resolver(Powrup)
9
+ export class PowrupQuery {
10
+ @Query(returns => Powrup, { description: 'To fetch a Powrup' })
11
+ async powrup(@Arg('id') id: string, @Ctx() context: any): Promise<Powrup> {
12
+ const { domain } = context.state
13
+
14
+ return await getRepository(Powrup).findOne({
15
+ where: { domain, id }
16
+ })
17
+ }
18
+
19
+ @Query(returns => PowrupList, { description: 'To fetch multiple Powrups' })
20
+ async powrups(@Args() params: ListParam, @Ctx() context: any): Promise<PowrupList> {
21
+ const { domain } = context.state
22
+
23
+ const convertedParams = convertListParams(params, domain.id)
24
+ const [items, total] = await getRepository(Powrup).findAndCount(convertedParams)
25
+
26
+ return { items, total }
27
+ }
28
+
29
+ @FieldResolver(type => Domain)
30
+ async domain(@Root() powrup: Powrup): Promise<Domain> {
31
+ return await getRepository(Domain).findOne(powrup.domainId)
32
+ }
33
+
34
+ @FieldResolver(type => User)
35
+ async updater(@Root() powrup: Powrup): Promise<User> {
36
+ return await getRepository(User).findOne(powrup.updaterId)
37
+ }
38
+
39
+ @FieldResolver(type => User)
40
+ async creator(@Root() powrup: Powrup): Promise<User> {
41
+ return await getRepository(User).findOne(powrup.creatorId)
42
+ }
43
+ }
@@ -0,0 +1,60 @@
1
+ import { Field, ID, InputType, Int, ObjectType } from 'type-graphql'
2
+
3
+ import { Platform, Powrup } from './powrup'
4
+
5
+ @InputType()
6
+ export class NewPowrup {
7
+ @Field()
8
+ name: string
9
+
10
+ @Field({ nullable: true })
11
+ description?: string
12
+
13
+ @Field(type => Platform, { nullable: true })
14
+ platform?: Platform
15
+
16
+ @Field({ nullable: true })
17
+ apiKey?: string
18
+
19
+ @Field({ nullable: true })
20
+ active?: boolean
21
+
22
+ @Field({ nullable: true })
23
+ staging?: boolean
24
+ }
25
+
26
+ @InputType()
27
+ export class PowrupPatch {
28
+ @Field(type => ID, { nullable: true })
29
+ id?: string
30
+
31
+ @Field({ nullable: true })
32
+ name?: string
33
+
34
+ @Field({ nullable: true })
35
+ description?: string
36
+
37
+ @Field(type => Platform, { nullable: true })
38
+ platform?: Platform
39
+
40
+ @Field({ nullable: true })
41
+ apiKey?: string
42
+
43
+ @Field({ nullable: true })
44
+ active?: boolean
45
+
46
+ @Field({ nullable: true })
47
+ staging?: boolean
48
+
49
+ @Field()
50
+ cuFlag: string
51
+ }
52
+
53
+ @ObjectType()
54
+ export class PowrupList {
55
+ @Field(type => [Powrup])
56
+ items: Powrup[]
57
+
58
+ @Field(type => Int)
59
+ total: number
60
+ }
@@ -0,0 +1,113 @@
1
+ import { Field, ID, ObjectType, registerEnumType } from 'type-graphql'
2
+ import {
3
+ Column,
4
+ CreateDateColumn,
5
+ Entity,
6
+ Index,
7
+ ManyToOne,
8
+ PrimaryGeneratedColumn,
9
+ RelationId,
10
+ UpdateDateColumn
11
+ } from 'typeorm'
12
+
13
+ import { User } from '@things-factory/auth-base'
14
+ import { config } from '@things-factory/env'
15
+ import { Domain } from '@things-factory/shell'
16
+
17
+ const ORMCONFIG = config.get('ormconfig', {})
18
+ const DATABASE_TYPE = ORMCONFIG.type
19
+
20
+ export enum Platform {
21
+ POWRUP = 'POWRUP',
22
+ POWRUP_INTERNAL = 'POWRUP_INTERNAL'
23
+ }
24
+
25
+ registerEnumType(Platform, {
26
+ name: 'Platform',
27
+ description: 'platform enumeration of a integration'
28
+ })
29
+
30
+ @Entity()
31
+ @Index('ix_powrup_0', (powrup: Powrup) => [powrup.domain, powrup.name], { unique: true })
32
+ @ObjectType({ description: 'Entity for Powrup' })
33
+ export class Powrup {
34
+ @PrimaryGeneratedColumn('uuid')
35
+ @Field(type => ID)
36
+ readonly id: string
37
+
38
+ @ManyToOne(type => Domain)
39
+ @Field({ nullable: true })
40
+ domain?: Domain
41
+
42
+ @RelationId((powrup: Powrup) => powrup.domain)
43
+ domainId?: string
44
+
45
+ @Column()
46
+ @Field()
47
+ name: string
48
+
49
+ @Column({
50
+ nullable: true
51
+ })
52
+ @Field({ nullable: true })
53
+ description?: string
54
+
55
+ @Column({
56
+ nullable: true,
57
+ default: false
58
+ })
59
+ @Field({ nullable: true })
60
+ active?: boolean
61
+
62
+ @Column({
63
+ type:
64
+ DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
65
+ ? 'enum'
66
+ : DATABASE_TYPE == 'oracle'
67
+ ? 'varchar2'
68
+ : 'smallint',
69
+ enum: Platform,
70
+ default: Platform.POWRUP
71
+ })
72
+ @Field()
73
+ platform: Platform
74
+
75
+ @Column({
76
+ nullable: true
77
+ })
78
+ @Field({ nullable: true })
79
+ apiKey?: string
80
+
81
+ @Column({
82
+ nullable: true,
83
+ default: false
84
+ })
85
+ @Field({ nullable: true })
86
+ staging?: boolean
87
+
88
+ @CreateDateColumn()
89
+ @Field({ nullable: true })
90
+ createdAt?: Date
91
+
92
+ @UpdateDateColumn()
93
+ @Field({ nullable: true })
94
+ updatedAt?: Date
95
+
96
+ @ManyToOne(type => User, {
97
+ nullable: true
98
+ })
99
+ @Field({ nullable: true })
100
+ creator?: User
101
+
102
+ @RelationId((powrup: Powrup) => powrup.creator)
103
+ creatorId?: string
104
+
105
+ @ManyToOne(type => User, {
106
+ nullable: true
107
+ })
108
+ @Field({ nullable: true })
109
+ updater?: User
110
+
111
+ @RelationId((powrup: Powrup) => powrup.creator)
112
+ updaterId?: string
113
+ }