@things-factory/accounting 8.0.0-beta.1 → 8.0.0-beta.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. package/package.json +5 -5
  2. package/client/activities/activity-book-edit.ts +0 -88
  3. package/client/activities/activity-book-view.ts +0 -88
  4. package/client/activities/activity-expense-edit.ts +0 -88
  5. package/client/activities/activity-expense-view.ts +0 -88
  6. package/client/bootstrap.ts +0 -10
  7. package/client/components/accounting-category-selector.ts +0 -136
  8. package/client/components/accounting-category-view.ts +0 -75
  9. package/client/grist-editors/grist-editor-accounting-category-object.ts +0 -83
  10. package/client/grist-editors/grist-renderer-accounting-category-object.ts +0 -13
  11. package/client/index.ts +0 -0
  12. package/client/pages/account/account-importer.ts +0 -97
  13. package/client/pages/account/account-list-page.ts +0 -364
  14. package/client/pages/accounting-category/accounting-category-importer.ts +0 -97
  15. package/client/pages/accounting-category/accounting-category-list-page.ts +0 -368
  16. package/client/pages/accounting-category/accounting-category-tree-page.ts +0 -338
  17. package/client/pages/accounting-document/accounting-document-importer.ts +0 -90
  18. package/client/pages/accounting-document/accounting-document-list-page.ts +0 -398
  19. package/client/pages/bank/bank-importer.ts +0 -90
  20. package/client/pages/bank/bank-list-page.ts +0 -398
  21. package/client/pages/bank-account/bank-account-importer.ts +0 -90
  22. package/client/pages/bank-account/bank-account-list-page.ts +0 -398
  23. package/client/pages/financial-institution/financial-institution-importer.ts +0 -90
  24. package/client/pages/financial-institution/financial-institution-list-page.ts +0 -398
  25. package/client/pages/financial-statement/financial-statement-importer.ts +0 -97
  26. package/client/pages/financial-statement/financial-statement-list-page.ts +0 -338
  27. package/client/pages/fiscal-month/fiscal-month-importer.ts +0 -90
  28. package/client/pages/fiscal-month/fiscal-month-list-page.ts +0 -398
  29. package/client/pages/fiscal-quarter/fiscal-quarter-importer.ts +0 -90
  30. package/client/pages/fiscal-quarter/fiscal-quarter-list-page.ts +0 -398
  31. package/client/pages/fiscal-year/fiscal-year-importer.ts +0 -90
  32. package/client/pages/fiscal-year/fiscal-year-list-page.ts +0 -398
  33. package/client/pages/income-statement/income-statement-importer.ts +0 -97
  34. package/client/pages/income-statement/income-statement-list-page.ts +0 -338
  35. package/client/pages/payment/payment-importer.ts +0 -90
  36. package/client/pages/payment/payment-list-page.ts +0 -398
  37. package/client/pages/transaction/transaction-importer.ts +0 -97
  38. package/client/pages/transaction/transaction-list-page.ts +0 -338
  39. package/client/route.ts +0 -35
  40. package/client/tsconfig.json +0 -13
  41. package/client/types/accounting-category.ts +0 -23
  42. package/client/types/index.ts +0 -1
  43. package/server/activities/activity-book.ts +0 -172
  44. package/server/activities/activity-expense.ts +0 -149
  45. package/server/activities/index.ts +0 -18
  46. package/server/controllers/index.ts +0 -1
  47. package/server/controllers/summary-statements.ts +0 -166
  48. package/server/index.ts +0 -6
  49. package/server/middlewares/index.ts +0 -3
  50. package/server/migrations/1725200507196-seed-fiscal-entities.ts +0 -106
  51. package/server/migrations/1725201467183-seed-accounts.ts +0 -339
  52. package/server/migrations/1725201567284-seed-country-codes.ts +0 -261
  53. package/server/migrations/1725201667385-seed-financial-institutions.ts +0 -348
  54. package/server/migrations/index.ts +0 -9
  55. package/server/routes.ts +0 -26
  56. package/server/service/account/account-history.ts +0 -117
  57. package/server/service/account/account-mutation.ts +0 -140
  58. package/server/service/account/account-query.ts +0 -51
  59. package/server/service/account/account-type.ts +0 -44
  60. package/server/service/account/account.ts +0 -97
  61. package/server/service/account/event-subscriber.ts +0 -17
  62. package/server/service/account/index.ts +0 -9
  63. package/server/service/accounting-category/accounting-category-history.ts +0 -129
  64. package/server/service/accounting-category/accounting-category-mutation.ts +0 -148
  65. package/server/service/accounting-category/accounting-category-query.ts +0 -74
  66. package/server/service/accounting-category/accounting-category-type.ts +0 -48
  67. package/server/service/accounting-category/accounting-category.ts +0 -100
  68. package/server/service/accounting-category/event-subscriber.ts +0 -20
  69. package/server/service/accounting-category/index.ts +0 -9
  70. package/server/service/accounting-document/accounting-document-history.ts +0 -123
  71. package/server/service/accounting-document/accounting-document-mutation.ts +0 -137
  72. package/server/service/accounting-document/accounting-document-query.ts +0 -48
  73. package/server/service/accounting-document/accounting-document-type.ts +0 -52
  74. package/server/service/accounting-document/accounting-document.ts +0 -93
  75. package/server/service/accounting-document/event-subscriber.ts +0 -17
  76. package/server/service/accounting-document/index.ts +0 -9
  77. package/server/service/bank-account/bank-account-history.ts +0 -149
  78. package/server/service/bank-account/bank-account-mutation.ts +0 -137
  79. package/server/service/bank-account/bank-account-query.ts +0 -48
  80. package/server/service/bank-account/bank-account-type.ts +0 -112
  81. package/server/service/bank-account/bank-account.ts +0 -142
  82. package/server/service/bank-account/event-subscriber.ts +0 -17
  83. package/server/service/bank-account/index.ts +0 -9
  84. package/server/service/common-type.ts +0 -12
  85. package/server/service/financial-institution/financial-institution-mutation.ts +0 -198
  86. package/server/service/financial-institution/financial-institution-query.ts +0 -62
  87. package/server/service/financial-institution/financial-institution-type.ts +0 -91
  88. package/server/service/financial-institution/financial-institution.ts +0 -122
  89. package/server/service/financial-institution/index.ts +0 -7
  90. package/server/service/financial-statement/event-subscriber.ts +0 -17
  91. package/server/service/financial-statement/financial-statement-history.ts +0 -129
  92. package/server/service/financial-statement/financial-statement-line-item.ts +0 -82
  93. package/server/service/financial-statement/financial-statement-mutation.ts +0 -148
  94. package/server/service/financial-statement/financial-statement-query.ts +0 -53
  95. package/server/service/financial-statement/financial-statement-type.ts +0 -51
  96. package/server/service/financial-statement/financial-statement.ts +0 -116
  97. package/server/service/financial-statement/index.ts +0 -10
  98. package/server/service/fiscal-month/fiscal-month-mutation.ts +0 -145
  99. package/server/service/fiscal-month/fiscal-month-query.ts +0 -58
  100. package/server/service/fiscal-month/fiscal-month-type.ts +0 -66
  101. package/server/service/fiscal-month/fiscal-month.ts +0 -84
  102. package/server/service/fiscal-month/index.ts +0 -7
  103. package/server/service/fiscal-quarter/fiscal-quarter-mutation.ts +0 -148
  104. package/server/service/fiscal-quarter/fiscal-quarter-query.ts +0 -60
  105. package/server/service/fiscal-quarter/fiscal-quarter-type.ts +0 -60
  106. package/server/service/fiscal-quarter/fiscal-quarter.ts +0 -80
  107. package/server/service/fiscal-quarter/index.ts +0 -7
  108. package/server/service/fiscal-year/fiscal-year-mutation.ts +0 -145
  109. package/server/service/fiscal-year/fiscal-year-query.ts +0 -53
  110. package/server/service/fiscal-year/fiscal-year-type.ts +0 -54
  111. package/server/service/fiscal-year/fiscal-year.ts +0 -76
  112. package/server/service/fiscal-year/index.ts +0 -7
  113. package/server/service/income-statement/event-subscriber.ts +0 -17
  114. package/server/service/income-statement/income-statement-history.ts +0 -133
  115. package/server/service/income-statement/income-statement-line-item.ts +0 -84
  116. package/server/service/income-statement/income-statement-mutation.ts +0 -147
  117. package/server/service/income-statement/income-statement-query.ts +0 -50
  118. package/server/service/income-statement/income-statement-type.ts +0 -51
  119. package/server/service/income-statement/income-statement.ts +0 -120
  120. package/server/service/income-statement/index.ts +0 -10
  121. package/server/service/index.ts +0 -108
  122. package/server/service/payment/event-subscriber.ts +0 -17
  123. package/server/service/payment/index.ts +0 -9
  124. package/server/service/payment/payment-history.ts +0 -155
  125. package/server/service/payment/payment-mutation.ts +0 -139
  126. package/server/service/payment/payment-query.ts +0 -50
  127. package/server/service/payment/payment-type.ts +0 -82
  128. package/server/service/payment/payment.ts +0 -154
  129. package/server/service/transaction/event-subscriber.ts +0 -17
  130. package/server/service/transaction/index.ts +0 -9
  131. package/server/service/transaction/transaction-history.ts +0 -161
  132. package/server/service/transaction/transaction-mutation.ts +0 -146
  133. package/server/service/transaction/transaction-query.ts +0 -50
  134. package/server/service/transaction/transaction-type.ts +0 -48
  135. package/server/service/transaction/transaction.ts +0 -230
  136. package/server/tsconfig.json +0 -10
@@ -1,154 +0,0 @@
1
- import {
2
- CreateDateColumn,
3
- UpdateDateColumn,
4
- DeleteDateColumn,
5
- Entity,
6
- Index,
7
- Column,
8
- RelationId,
9
- ManyToOne,
10
- VersionColumn,
11
- PrimaryGeneratedColumn
12
- } from 'typeorm'
13
- import { ObjectType, Field, ID, registerEnumType } from 'type-graphql'
14
-
15
- import { Domain } from '@things-factory/shell'
16
- import { User } from '@things-factory/auth-base'
17
- import { Transaction } from '../transaction/transaction'
18
- import { BankAccount } from 'service/bank-account/bank-account'
19
-
20
- export enum PaymentDirection {
21
- Incoming = 'Incoming', // 수금
22
- Outgoing = 'Outgoing' // 지출
23
- }
24
-
25
- registerEnumType(PaymentDirection, {
26
- name: 'PaymentDirection',
27
- description: 'Indicates whether the payment is incoming (received) or outgoing (paid)' // 결제 방향을 나타냅니다 (수금 또는 지출)
28
- })
29
-
30
- export enum PaymentType {
31
- Transfer = 'Transfer', // 계좌 이체
32
- Cash = 'Cash', // 현금
33
- CreditCard = 'CreditCard', // 신용카드
34
- DebitCard = 'DebitCard' // 직불카드
35
- }
36
-
37
- registerEnumType(PaymentType, {
38
- name: 'PaymentType',
39
- description: 'Type of the payment (e.g., Transfer, Cash, CreditCard, DebitCard)' // 결제 유형을 나타냅니다
40
- })
41
-
42
- @Entity()
43
- @Index('ix_payment_0', (payment: Payment) => [payment.domain, payment.transaction, payment.paidAt], {
44
- where: '"deleted_at" IS NULL',
45
- unique: true
46
- })
47
- @Index(
48
- 'ix_payment_1',
49
- (payment: Payment) => [payment.domain, payment.year, payment.quarter, payment.month, payment.paidAt],
50
- {
51
- unique: true,
52
- where: '"deleted_at" IS NULL'
53
- }
54
- )
55
- @ObjectType({ description: 'Entity representing a Payment record in the system' }) // 시스템 내에서 결제 기록을 나타내는 엔티티
56
- export class Payment {
57
- @PrimaryGeneratedColumn('uuid')
58
- @Field(type => ID, { description: 'Unique identifier for the payment record' })
59
- readonly id: string // 고유 식별자 (UUID)
60
-
61
- @VersionColumn()
62
- @Field({ nullable: true, description: 'Version number used for optimistic locking' })
63
- version?: number = 1 // 낙관적 잠금을 위한 버전 관리 필드
64
-
65
- @ManyToOne(type => Domain)
66
- @Field({ nullable: true, description: 'The domain to which this payment belongs' })
67
- domain?: Domain // 결제가 속한 도메인
68
-
69
- @RelationId((payment: Payment) => payment.domain)
70
- domainId?: string // 도메인의 ID
71
-
72
- @ManyToOne(type => Transaction, transaction => transaction.payments)
73
- @Field(type => Transaction, { description: 'The transaction associated with this payment' })
74
- transaction: Transaction // 결제와 연결된 트랜잭션
75
-
76
- @RelationId((payment: Payment) => payment.transaction)
77
- transactionId: string // 연결된 트랜잭션의 ID
78
-
79
- @Column({ nullable: true })
80
- @Field({ nullable: true, description: 'The currency used in the payment' })
81
- currency?: string // 결제에 사용된 통화
82
-
83
- @Column({ nullable: false })
84
- @Field({ nullable: false, description: 'The amount of money involved in the payment' })
85
- amount: number // 결제된 금액
86
-
87
- @Column({ type: 'enum', enum: PaymentType, nullable: false })
88
- @Field(type => PaymentType, { description: 'Type of the payment' })
89
- paymentType: PaymentType // 결제 유형
90
-
91
- @ManyToOne(type => BankAccount, { nullable: true })
92
- @Field(type => BankAccount, { nullable: true, description: 'Source bank account for the payment' })
93
- sourceBankAccount?: BankAccount
94
-
95
- @RelationId((payment: Payment) => payment.sourceBankAccount)
96
- sourceBankAccountId?: string
97
-
98
- @ManyToOne(type => BankAccount, { nullable: true })
99
- @Field(type => BankAccount, { nullable: true, description: 'Destination bank account for the payment' })
100
- destinationBankAccount?: BankAccount
101
-
102
- @RelationId((payment: Payment) => payment.destinationBankAccount)
103
- destinationBankAccountId?: string
104
-
105
- @Column({ nullable: true })
106
- @Field({ nullable: true, description: 'Fiscal year in which the payment was made' })
107
- year?: number // 결제가 발생한 회계 연도
108
-
109
- @Column({ nullable: true })
110
- @Field({ nullable: true, description: 'Fiscal quarter in which the payment was made' })
111
- quarter?: number // 결제가 발생한 회계 분기
112
-
113
- @Column({ nullable: true })
114
- @Field({ nullable: true, description: 'Fiscal month in which the payment was made' })
115
- month?: number // 결제가 발생한 회계 월
116
-
117
- @Column({ nullable: false })
118
- @Field({ nullable: false, description: 'The date and time when the payment was made' })
119
- paidAt: Date // 결제가 이루어진 날짜 및 시간
120
-
121
- @Column({ nullable: false })
122
- @Field(type => PaymentDirection, { description: 'Direction of the payment (Incoming or Outgoing)' })
123
- direction: PaymentDirection // 결제 방향 (수금 또는 지출)
124
-
125
- @Column({ nullable: true })
126
- @Field({ nullable: true, description: 'Additional notes or comments about the payment' })
127
- note?: string // 결제에 대한 추가 설명 또는 메모
128
-
129
- @CreateDateColumn()
130
- @Field({ nullable: true, description: 'The date and time when the payment record was created' })
131
- createdAt?: Date // 결제 레코드가 생성된 날짜 및 시간
132
-
133
- @UpdateDateColumn()
134
- @Field({ nullable: true, description: 'The date and time when the payment record was last updated' })
135
- updatedAt?: Date // 결제 레코드가 마지막으로 업데이트된 날짜 및 시간
136
-
137
- @DeleteDateColumn()
138
- @Field({ nullable: true, description: 'The date and time when the payment record was deleted' })
139
- deletedAt?: Date // 결제 레코드가 삭제된 날짜 및 시간
140
-
141
- @ManyToOne(type => User, { nullable: true })
142
- @Field(type => User, { nullable: true, description: 'The user who created the payment record' })
143
- creator?: User // 결제 레코드를 생성한 사용자
144
-
145
- @RelationId((payment: Payment) => payment.creator)
146
- creatorId?: string // 결제 레코드를 생성한 사용자의 ID
147
-
148
- @ManyToOne(type => User, { nullable: true })
149
- @Field(type => User, { nullable: true, description: 'The user who last updated the payment record' })
150
- updater?: User // 결제 레코드를 마지막으로 업데이트한 사용자
151
-
152
- @RelationId((payment: Payment) => payment.updater)
153
- updaterId?: string // 결제 레코드를 업데이트한 사용자의 ID
154
- }
@@ -1,17 +0,0 @@
1
- import { EventSubscriber } from 'typeorm'
2
-
3
- import { HistoryEntitySubscriber } from '@operato/typeorm-history'
4
-
5
- import { Transaction } from './transaction'
6
- import { TransactionHistory } from './transaction-history'
7
-
8
- @EventSubscriber()
9
- export class TransactionHistoryEntitySubscriber extends HistoryEntitySubscriber<Transaction, TransactionHistory> {
10
- public get entity() {
11
- return Transaction
12
- }
13
-
14
- public get historyEntity() {
15
- return TransactionHistory
16
- }
17
- }
@@ -1,9 +0,0 @@
1
- import { Transaction } from './transaction'
2
- import { TransactionHistory } from './transaction-history'
3
- import { TransactionQuery } from './transaction-query'
4
- import { TransactionMutation } from './transaction-mutation'
5
- import { TransactionHistoryEntitySubscriber } from './event-subscriber'
6
-
7
- export const entities = [Transaction, TransactionHistory]
8
- export const resolvers = [TransactionQuery, TransactionMutation]
9
- export const subscribers = [TransactionHistoryEntitySubscriber]
@@ -1,161 +0,0 @@
1
- import { Field, ID, ObjectType } from 'type-graphql'
2
- import { Column, Entity, Index, ManyToOne, PrimaryGeneratedColumn, RelationId } from 'typeorm'
3
-
4
- import {
5
- HistoryActionColumn,
6
- HistoryActionType,
7
- HistoryEntityInterface,
8
- HistoryOriginalIdColumn
9
- } from '@operato/typeorm-history'
10
- import { Role, User } from '@things-factory/auth-base'
11
- import { config } from '@things-factory/env'
12
- import { Domain } from '@things-factory/shell'
13
-
14
- import { Transaction, TransactionCategory, TransactionStatus, TransactionType } from './transaction'
15
- import { Account } from '../account/account'
16
-
17
- const ORMCONFIG = config.get('ormconfig', {})
18
- const DATABASE_TYPE = ORMCONFIG.type
19
-
20
- @Entity()
21
- @Index(
22
- 'ix_transaction_history_0',
23
- (transactionHistory: TransactionHistory) => [transactionHistory.originalId, transactionHistory.version],
24
- { unique: true }
25
- )
26
- @Index(
27
- 'ix_transaction_history_1',
28
- (transactionHistory: TransactionHistory) => [
29
- transactionHistory.domain,
30
- transactionHistory.originalId,
31
- transactionHistory.version
32
- ],
33
- { unique: true }
34
- )
35
- @ObjectType({ description: 'History Entity of Transaction' })
36
- export class TransactionHistory implements HistoryEntityInterface<Transaction> {
37
- @PrimaryGeneratedColumn('uuid')
38
- @Field(type => ID)
39
- readonly id: string
40
-
41
- @Column({ nullable: true, default: 1 })
42
- @Field({ nullable: true })
43
- version?: number = 1
44
-
45
- @ManyToOne(type => Domain)
46
- @Field({ nullable: true })
47
- domain?: Domain
48
-
49
- @RelationId((transactionHistory: TransactionHistory) => transactionHistory.domain)
50
- domainId?: string
51
-
52
- @Column()
53
- @Field({ nullable: true })
54
- name?: string
55
-
56
- @Column({ nullable: true })
57
- @Field({ nullable: true })
58
- description?: string
59
-
60
- @Column({ nullable: true })
61
- @Field({ nullable: true })
62
- currency?: string
63
-
64
- @Column({ nullable: true })
65
- @Field({ nullable: true })
66
- amount?: number = 0
67
-
68
- @Column({ nullable: true })
69
- @Field({ nullable: true })
70
- active?: boolean
71
-
72
- @Column({ nullable: true })
73
- @Field({ nullable: true })
74
- type?: TransactionType
75
-
76
- @Column({ nullable: false })
77
- @Field(type => TransactionCategory, { nullable: false })
78
- category: TransactionCategory // 트랜잭션의 카테고리 (확정, 전망)
79
-
80
- @Column({ nullable: false })
81
- @Field(type => TransactionStatus, { nullable: false })
82
- status: TransactionStatus // 트랜잭션의 상태 (예: Paid, Delayed 등)
83
-
84
- @Column({ nullable: true })
85
- @Field({ nullable: true, description: 'The probability of the forecast being realized (0 to 100)' })
86
- probability?: number // 예측이 실현될 확률 (0 ~ 100)
87
-
88
- @Column({ nullable: true })
89
- @Field({ nullable: true, description: 'Additional notes or comments about the forecast' })
90
- forecastNotes?: string // 전망에 대한 추가 설명이나 메모
91
-
92
- @ManyToOne(type => Account)
93
- @Field({ nullable: true })
94
- account?: Account
95
-
96
- @RelationId((transactionHistory: TransactionHistory) => transactionHistory.account)
97
- accountId?: string
98
-
99
- @Column({ nullable: true })
100
- @Field({ nullable: true, description: 'fiscal year' })
101
- year?: number
102
-
103
- @Column({ nullable: true })
104
- @Field({ nullable: true, description: 'fiscal quarter' })
105
- quarter?: number
106
-
107
- @Column({ nullable: true })
108
- @Field({ nullable: true, description: 'fiscal month' })
109
- month?: number
110
-
111
- @Column({ nullable: false })
112
- @Field({ nullable: false, description: 'The date the transaction occurs or is scheduled (in string format)' })
113
- transactionDate: string // 트랜잭션이 발생하거나 발생할 날짜
114
-
115
- @Column()
116
- @Field({ nullable: true })
117
- createdAt?: Date
118
-
119
- @Column()
120
- @Field({ nullable: true })
121
- updatedAt?: Date
122
-
123
- @Column()
124
- @Field({ nullable: true })
125
- deletedAt?: Date
126
-
127
- @ManyToOne(type => User, { nullable: true })
128
- @Field(type => User, { nullable: true })
129
- creator?: User
130
-
131
- @RelationId((transactionHistory: TransactionHistory) => transactionHistory.creator)
132
- creatorId?: string
133
-
134
- @ManyToOne(type => User, { nullable: true })
135
- @Field(type => User, { nullable: true })
136
- updater?: User
137
-
138
- @RelationId((transactionHistory: TransactionHistory) => transactionHistory.updater)
139
- updaterId?: string
140
-
141
- @HistoryOriginalIdColumn()
142
- public originalId!: string
143
-
144
- @HistoryActionColumn({
145
- nullable: false,
146
- type:
147
- DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
148
- ? 'enum'
149
- : DATABASE_TYPE == 'oracle'
150
- ? 'varchar2'
151
- : DATABASE_TYPE == 'mssql'
152
- ? 'nvarchar'
153
- : 'varchar',
154
- enum:
155
- DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
156
- ? HistoryActionType
157
- : undefined,
158
- length: DATABASE_TYPE == 'postgres' || DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb' ? undefined : 10
159
- })
160
- public action!: HistoryActionType
161
- }
@@ -1,146 +0,0 @@
1
- import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'
2
- import { In } from 'typeorm'
3
-
4
- import { getRepository } from '@things-factory/shell'
5
-
6
- import { Transaction } from './transaction'
7
- import { NewTransaction, TransactionPatch } from './transaction-type'
8
-
9
- @Resolver(Transaction)
10
- export class TransactionMutation {
11
- @Directive('@transaction')
12
- @Directive('@privilege(category: "accounting", privilege: "mutation")')
13
- @Mutation(returns => Transaction, { description: 'To create new Transaction' })
14
- async createTransaction(
15
- @Arg('transaction') transaction: NewTransaction,
16
- @Ctx() context: ResolverContext
17
- ): Promise<Transaction> {
18
- const { domain, user, tx } = context.state
19
-
20
- const result = await getRepository(Transaction, tx).save({
21
- ...transaction,
22
- domain,
23
- creator: user,
24
- updater: user
25
- })
26
-
27
- return result
28
- }
29
-
30
- @Directive('@transaction')
31
- @Directive('@privilege(category: "accounting", privilege: "mutation")')
32
- @Mutation(returns => Transaction, { description: 'To modify Transaction information' })
33
- async updateTransaction(
34
- @Arg('id') id: string,
35
- @Arg('patch') patch: TransactionPatch,
36
- @Ctx() context: ResolverContext
37
- ): Promise<Transaction> {
38
- const { domain, user, tx } = context.state
39
-
40
- const repository = getRepository(Transaction, tx)
41
- const transaction = await repository.findOne({
42
- where: { domain: { id: domain.id }, id }
43
- })
44
-
45
- const result = await repository.save({
46
- ...transaction,
47
- ...patch,
48
- updater: user
49
- })
50
-
51
- return result
52
- }
53
-
54
- @Directive('@transaction')
55
- @Directive('@privilege(category: "accounting", privilege: "mutation")')
56
- @Mutation(returns => [Transaction], { description: "To modify multiple Transactions' information" })
57
- async updateMultipleTransaction(
58
- @Arg('patches', type => [TransactionPatch]) patches: TransactionPatch[],
59
- @Ctx() context: ResolverContext
60
- ): Promise<Transaction[]> {
61
- const { domain, user, tx } = context.state
62
-
63
- let results = []
64
- const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
65
- const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
66
- const transactionRepo = getRepository(Transaction, tx)
67
-
68
- if (_createRecords.length > 0) {
69
- for (let i = 0; i < _createRecords.length; i++) {
70
- const newRecord = _createRecords[i]
71
-
72
- const result = await transactionRepo.save({
73
- ...newRecord,
74
- domain,
75
- creator: user,
76
- updater: user
77
- })
78
-
79
- results.push({ ...result, cuFlag: '+' })
80
- }
81
- }
82
-
83
- if (_updateRecords.length > 0) {
84
- for (let i = 0; i < _updateRecords.length; i++) {
85
- const updateRecord = _updateRecords[i]
86
- const transaction = await transactionRepo.findOneBy({ id: updateRecord.id })
87
-
88
- const result = await transactionRepo.save({
89
- ...transaction,
90
- ...updateRecord,
91
- updater: user
92
- })
93
-
94
- results.push({ ...result, cuFlag: 'M' })
95
- }
96
- }
97
-
98
- return results
99
- }
100
-
101
- @Directive('@transaction')
102
- @Directive('@privilege(category: "accounting", privilege: "mutation")')
103
- @Mutation(returns => Boolean, { description: 'To delete Transaction' })
104
- async deleteTransaction(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
105
- const { domain, tx } = context.state
106
-
107
- await getRepository(Transaction, tx).delete({ domain: { id: domain.id }, id })
108
-
109
- return true
110
- }
111
-
112
- @Directive('@transaction')
113
- @Directive('@privilege(category: "accounting", privilege: "mutation")')
114
- @Mutation(returns => Boolean, { description: 'To delete multiple Transactions' })
115
- async deleteTransactions(
116
- @Arg('ids', type => [String]) ids: string[],
117
- @Ctx() context: ResolverContext
118
- ): Promise<boolean> {
119
- const { domain, tx } = context.state
120
-
121
- await getRepository(Transaction, tx).delete({
122
- domain: { id: domain.id },
123
- id: In(ids)
124
- })
125
-
126
- return true
127
- }
128
-
129
- @Directive('@transaction')
130
- @Directive('@privilege(category: "accounting", privilege: "mutation")')
131
- @Mutation(returns => Boolean, { description: 'To import multiple Transactions' })
132
- async importTransactions(
133
- @Arg('transactions', type => [TransactionPatch]) transactions: TransactionPatch[],
134
- @Ctx() context: ResolverContext
135
- ): Promise<boolean> {
136
- const { domain, tx } = context.state
137
-
138
- await Promise.all(
139
- transactions.map(async (transaction: TransactionPatch) => {
140
- const createdTransaction: Transaction = await getRepository(Transaction, tx).save({ domain, ...transaction })
141
- })
142
- )
143
-
144
- return true
145
- }
146
- }
@@ -1,50 +0,0 @@
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 { Transaction } from './transaction'
5
- import { TransactionList } from './transaction-type'
6
-
7
- @Resolver(Transaction)
8
- export class TransactionQuery {
9
- @Directive('@privilege(category: "accounting", privilege: "query")')
10
- @Query(returns => Transaction!, { nullable: true, description: 'To fetch a Transaction' })
11
- async transaction(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<Transaction> {
12
- const { domain } = context.state
13
-
14
- return await getRepository(Transaction).findOne({
15
- where: { domain: { id: domain.id }, id }
16
- })
17
- }
18
-
19
- @Directive('@privilege(category: "accounting", privilege: "query")')
20
- @Query(returns => TransactionList, { description: 'To fetch multiple Transactions' })
21
- async transactions(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<TransactionList> {
22
- const { domain } = context.state
23
-
24
- const queryBuilder = getQueryBuilderFromListParams({
25
- domain,
26
- params,
27
- repository: await getRepository(Transaction),
28
- searchables: ['name', 'description']
29
- })
30
-
31
- const [items, total] = await queryBuilder.getManyAndCount()
32
-
33
- return { items, total }
34
- }
35
-
36
- @FieldResolver(type => Domain)
37
- async domain(@Root() transaction: Transaction): Promise<Domain> {
38
- return await getRepository(Domain).findOneBy({ id: transaction.domainId })
39
- }
40
-
41
- @FieldResolver(type => User)
42
- async updater(@Root() transaction: Transaction): Promise<User> {
43
- return await getRepository(User).findOneBy({ id: transaction.updaterId })
44
- }
45
-
46
- @FieldResolver(type => User)
47
- async creator(@Root() transaction: Transaction): Promise<User> {
48
- return await getRepository(User).findOneBy({ id: transaction.creatorId })
49
- }
50
- }
@@ -1,48 +0,0 @@
1
- import { ObjectType, Field, InputType, Int, ID, registerEnumType } from 'type-graphql'
2
-
3
- import { Transaction, TransactionType } from './transaction'
4
-
5
- @InputType()
6
- export class NewTransaction {
7
- @Field()
8
- name: string
9
-
10
- @Field({ nullable: true })
11
- description?: string
12
-
13
- @Field(type => TransactionType, { nullable: true })
14
- type?: TransactionType
15
-
16
- @Field({ nullable: true })
17
- active?: boolean
18
- }
19
-
20
- @InputType()
21
- export class TransactionPatch {
22
- @Field(type => ID, { nullable: true })
23
- id?: string
24
-
25
- @Field({ nullable: true })
26
- name?: string
27
-
28
- @Field({ nullable: true })
29
- description?: string
30
-
31
- @Field(type => TransactionType, { nullable: true })
32
- type?: TransactionType
33
-
34
- @Field({ nullable: true })
35
- active?: boolean
36
-
37
- @Field({ nullable: true })
38
- cuFlag?: string
39
- }
40
-
41
- @ObjectType()
42
- export class TransactionList {
43
- @Field(type => [Transaction])
44
- items: Transaction[]
45
-
46
- @Field(type => Int)
47
- total: number
48
- }