@stamhoofd/models 2.39.0 → 2.40.0

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 (352) hide show
  1. package/dist/src/factories/AddressFactory.d.ts +3 -4
  2. package/dist/src/factories/AddressFactory.d.ts.map +1 -1
  3. package/dist/src/factories/AddressFactory.js +13 -13
  4. package/dist/src/factories/EmergencyContactFactory.d.ts +3 -4
  5. package/dist/src/factories/EmergencyContactFactory.d.ts.map +1 -1
  6. package/dist/src/factories/EmergencyContactFactory.js +27 -27
  7. package/dist/src/factories/EmergencyContactFactory.js.map +1 -1
  8. package/dist/src/factories/GroupFactory.d.ts +4 -4
  9. package/dist/src/factories/GroupFactory.d.ts.map +1 -1
  10. package/dist/src/factories/GroupFactory.js +8 -8
  11. package/dist/src/factories/GroupFactory.js.map +1 -1
  12. package/dist/src/factories/MemberFactory.d.ts +4 -4
  13. package/dist/src/factories/MemberFactory.d.ts.map +1 -1
  14. package/dist/src/factories/MemberFactory.js +17 -17
  15. package/dist/src/factories/MemberFactory.js.map +1 -1
  16. package/dist/src/factories/OrganizationFactory.d.ts +4 -4
  17. package/dist/src/factories/OrganizationFactory.js +8 -8
  18. package/dist/src/factories/OrganizationFactory.js.map +1 -1
  19. package/dist/src/factories/ParentFactory.d.ts +1 -1
  20. package/dist/src/factories/ParentFactory.js +19 -19
  21. package/dist/src/factories/ParentFactory.js.map +1 -1
  22. package/dist/src/factories/RecordFactory.d.ts +2 -3
  23. package/dist/src/factories/RecordFactory.d.ts.map +1 -1
  24. package/dist/src/factories/RecordFactory.js +1 -1
  25. package/dist/src/factories/RecordFactory.js.map +1 -1
  26. package/dist/src/factories/RegisterCodeFactory.d.ts +2 -2
  27. package/dist/src/factories/RegisterCodeFactory.d.ts.map +1 -1
  28. package/dist/src/factories/RegisterCodeFactory.js +2 -2
  29. package/dist/src/factories/RegistrationFactory.d.ts +3 -3
  30. package/dist/src/factories/RegistrationFactory.d.ts.map +1 -1
  31. package/dist/src/factories/RegistrationFactory.js.map +1 -1
  32. package/dist/src/factories/RegistrationPeriodFactory.d.ts +2 -2
  33. package/dist/src/factories/RegistrationPeriodFactory.js.map +1 -1
  34. package/dist/src/factories/UserFactory.d.ts +3 -3
  35. package/dist/src/factories/UserFactory.d.ts.map +1 -1
  36. package/dist/src/factories/UserFactory.js +3 -3
  37. package/dist/src/factories/UserFactory.js.map +1 -1
  38. package/dist/src/factories/WebshopFactory.d.ts +4 -4
  39. package/dist/src/factories/WebshopFactory.d.ts.map +1 -1
  40. package/dist/src/factories/WebshopFactory.js +1 -1
  41. package/dist/src/factories/WebshopFactory.js.map +1 -1
  42. package/dist/src/helpers/DNSValidator.d.ts +1 -1
  43. package/dist/src/helpers/DNSValidator.d.ts.map +1 -1
  44. package/dist/src/helpers/DNSValidator.js +33 -33
  45. package/dist/src/helpers/DNSValidator.js.map +1 -1
  46. package/dist/src/helpers/EmailBuilder.d.ts +10 -10
  47. package/dist/src/helpers/EmailBuilder.d.ts.map +1 -1
  48. package/dist/src/helpers/EmailBuilder.js +34 -34
  49. package/dist/src/helpers/EmailBuilder.js.map +1 -1
  50. package/dist/src/helpers/GroupBuilder.d.ts.map +1 -1
  51. package/dist/src/helpers/GroupBuilder.js +57 -57
  52. package/dist/src/helpers/GroupBuilder.js.map +1 -1
  53. package/dist/src/helpers/Handlebars.d.ts.map +1 -1
  54. package/dist/src/helpers/Handlebars.js +29 -29
  55. package/dist/src/helpers/Handlebars.js.map +1 -1
  56. package/dist/src/helpers/MemberMerger.d.ts +1 -1
  57. package/dist/src/helpers/MemberMerger.d.ts.map +1 -1
  58. package/dist/src/helpers/MemberMerger.js +33 -33
  59. package/dist/src/helpers/MemberMerger.js.map +1 -1
  60. package/dist/src/helpers/MemberMerger.test.js +194 -194
  61. package/dist/src/helpers/MemberMerger.test.js.map +1 -1
  62. package/dist/src/helpers/RateLimiter.d.ts.map +1 -1
  63. package/dist/src/helpers/RateLimiter.js +2 -2
  64. package/dist/src/helpers/RateLimiter.js.map +1 -1
  65. package/dist/src/helpers/SetupStepsUpdater.d.ts +22 -0
  66. package/dist/src/helpers/SetupStepsUpdater.d.ts.map +1 -0
  67. package/dist/src/helpers/SetupStepsUpdater.js +255 -0
  68. package/dist/src/helpers/SetupStepsUpdater.js.map +1 -0
  69. package/dist/src/helpers/WebshopCounter.d.ts +1 -1
  70. package/dist/src/helpers/WebshopCounter.d.ts.map +1 -1
  71. package/dist/src/helpers/WebshopCounter.js +1 -1
  72. package/dist/src/helpers/WebshopCounter.js.map +1 -1
  73. package/dist/src/helpers/WebshopCounter.test.js +6 -6
  74. package/dist/src/helpers/WebshopCounter.test.js.map +1 -1
  75. package/dist/src/index.d.ts +20 -19
  76. package/dist/src/index.d.ts.map +1 -1
  77. package/dist/src/index.js +1 -0
  78. package/dist/src/index.js.map +1 -1
  79. package/dist/src/migrations/1605262045-import-postcodes.js +12 -12
  80. package/dist/src/migrations/1605262046-import-postcodes-nl.js +10 -10
  81. package/dist/src/models/BalanceItem.d.ts.map +1 -1
  82. package/dist/src/models/BalanceItem.js +37 -37
  83. package/dist/src/models/BalanceItem.js.map +1 -1
  84. package/dist/src/models/BalanceItemPayment.d.ts.map +1 -1
  85. package/dist/src/models/BalanceItemPayment.js +13 -13
  86. package/dist/src/models/BalanceItemPayment.js.map +1 -1
  87. package/dist/src/models/BuckarooPayment.d.ts +1 -1
  88. package/dist/src/models/BuckarooPayment.d.ts.map +1 -1
  89. package/dist/src/models/BuckarooPayment.js +5 -5
  90. package/dist/src/models/BuckarooPayment.js.map +1 -1
  91. package/dist/src/models/CachedOutstandingBalance.d.ts.map +1 -1
  92. package/dist/src/models/CachedOutstandingBalance.js +37 -37
  93. package/dist/src/models/CachedOutstandingBalance.js.map +1 -1
  94. package/dist/src/models/Document.d.ts +4 -4
  95. package/dist/src/models/Document.d.ts.map +1 -1
  96. package/dist/src/models/Document.js +27 -27
  97. package/dist/src/models/Document.js.map +1 -1
  98. package/dist/src/models/DocumentTemplate.d.ts +4 -4
  99. package/dist/src/models/DocumentTemplate.d.ts.map +1 -1
  100. package/dist/src/models/DocumentTemplate.js +72 -72
  101. package/dist/src/models/DocumentTemplate.js.map +1 -1
  102. package/dist/src/models/Email.d.ts.map +1 -1
  103. package/dist/src/models/Email.js +63 -64
  104. package/dist/src/models/Email.js.map +1 -1
  105. package/dist/src/models/EmailRecipient.d.ts.map +1 -1
  106. package/dist/src/models/EmailRecipient.js +20 -20
  107. package/dist/src/models/EmailRecipient.js.map +1 -1
  108. package/dist/src/models/EmailTemplate.d.ts +3 -3
  109. package/dist/src/models/EmailTemplate.d.ts.map +1 -1
  110. package/dist/src/models/EmailTemplate.js +16 -16
  111. package/dist/src/models/EmailTemplate.js.map +1 -1
  112. package/dist/src/models/EmailVerificationCode.d.ts +2 -2
  113. package/dist/src/models/EmailVerificationCode.d.ts.map +1 -1
  114. package/dist/src/models/EmailVerificationCode.js +57 -55
  115. package/dist/src/models/EmailVerificationCode.js.map +1 -1
  116. package/dist/src/models/Event.d.ts +2 -2
  117. package/dist/src/models/Event.d.ts.map +1 -1
  118. package/dist/src/models/Event.js +15 -15
  119. package/dist/src/models/Event.js.map +1 -1
  120. package/dist/src/models/Group.d.ts +3 -1
  121. package/dist/src/models/Group.d.ts.map +1 -1
  122. package/dist/src/models/Group.js +46 -35
  123. package/dist/src/models/Group.js.map +1 -1
  124. package/dist/src/models/Image.d.ts +1 -1
  125. package/dist/src/models/Image.d.ts.map +1 -1
  126. package/dist/src/models/Image.js +26 -26
  127. package/dist/src/models/Image.js.map +1 -1
  128. package/dist/src/models/Member.d.ts +8 -8
  129. package/dist/src/models/Member.d.ts.map +1 -1
  130. package/dist/src/models/Member.js +60 -60
  131. package/dist/src/models/Member.js.map +1 -1
  132. package/dist/src/models/MemberPlatformMembership.d.ts +3 -3
  133. package/dist/src/models/MemberPlatformMembership.d.ts.map +1 -1
  134. package/dist/src/models/MemberPlatformMembership.js +26 -26
  135. package/dist/src/models/MemberPlatformMembership.js.map +1 -1
  136. package/dist/src/models/MemberResponsibilityRecord.d.ts.map +1 -1
  137. package/dist/src/models/MemberResponsibilityRecord.js +13 -13
  138. package/dist/src/models/MemberResponsibilityRecord.js.map +1 -1
  139. package/dist/src/models/MergedMember.d.ts +3 -3
  140. package/dist/src/models/MergedMember.d.ts.map +1 -1
  141. package/dist/src/models/MergedMember.js +19 -19
  142. package/dist/src/models/MergedMember.js.map +1 -1
  143. package/dist/src/models/MolliePayment.d.ts +1 -1
  144. package/dist/src/models/MolliePayment.d.ts.map +1 -1
  145. package/dist/src/models/MolliePayment.js +5 -5
  146. package/dist/src/models/MolliePayment.js.map +1 -1
  147. package/dist/src/models/MollieToken.d.ts.map +1 -1
  148. package/dist/src/models/MollieToken.js +60 -60
  149. package/dist/src/models/MollieToken.js.map +1 -1
  150. package/dist/src/models/OneTimeToken.d.ts +2 -2
  151. package/dist/src/models/OneTimeToken.d.ts.map +1 -1
  152. package/dist/src/models/OneTimeToken.js +13 -13
  153. package/dist/src/models/OneTimeToken.js.map +1 -1
  154. package/dist/src/models/Order.d.ts +1 -1
  155. package/dist/src/models/Order.d.ts.map +1 -1
  156. package/dist/src/models/Order.js +70 -70
  157. package/dist/src/models/Order.js.map +1 -1
  158. package/dist/src/models/Organization.d.ts +5 -5
  159. package/dist/src/models/Organization.d.ts.map +1 -1
  160. package/dist/src/models/Organization.js +127 -127
  161. package/dist/src/models/Organization.js.map +1 -1
  162. package/dist/src/models/OrganizationRegistrationPeriod.d.ts.map +1 -1
  163. package/dist/src/models/OrganizationRegistrationPeriod.js +15 -15
  164. package/dist/src/models/OrganizationRegistrationPeriod.js.map +1 -1
  165. package/dist/src/models/PasswordToken.d.ts +3 -3
  166. package/dist/src/models/PasswordToken.d.ts.map +1 -1
  167. package/dist/src/models/PasswordToken.js +17 -17
  168. package/dist/src/models/PasswordToken.js.map +1 -1
  169. package/dist/src/models/PayconiqPayment.d.ts +1 -1
  170. package/dist/src/models/PayconiqPayment.d.ts.map +1 -1
  171. package/dist/src/models/PayconiqPayment.js +49 -49
  172. package/dist/src/models/PayconiqPayment.js.map +1 -1
  173. package/dist/src/models/Payment.d.ts +3 -3
  174. package/dist/src/models/Payment.d.ts.map +1 -1
  175. package/dist/src/models/Payment.js +36 -36
  176. package/dist/src/models/Payment.js.map +1 -1
  177. package/dist/src/models/Platform.d.ts +2 -2
  178. package/dist/src/models/Platform.d.ts.map +1 -1
  179. package/dist/src/models/Platform.js +8 -8
  180. package/dist/src/models/Platform.js.map +1 -1
  181. package/dist/src/models/RegisterCode.d.ts +1 -1
  182. package/dist/src/models/RegisterCode.d.ts.map +1 -1
  183. package/dist/src/models/RegisterCode.js +11 -11
  184. package/dist/src/models/RegisterCode.js.map +1 -1
  185. package/dist/src/models/Registration.d.ts +1 -1
  186. package/dist/src/models/Registration.d.ts.map +1 -1
  187. package/dist/src/models/Registration.js +88 -88
  188. package/dist/src/models/Registration.js.map +1 -1
  189. package/dist/src/models/RegistrationPeriod.d.ts.map +1 -1
  190. package/dist/src/models/RegistrationPeriod.js +12 -12
  191. package/dist/src/models/RegistrationPeriod.js.map +1 -1
  192. package/dist/src/models/STCredit.d.ts +1 -1
  193. package/dist/src/models/STCredit.d.ts.map +1 -1
  194. package/dist/src/models/STCredit.js +12 -12
  195. package/dist/src/models/STCredit.js.map +1 -1
  196. package/dist/src/models/STInvoice.d.ts +1 -1
  197. package/dist/src/models/STInvoice.d.ts.map +1 -1
  198. package/dist/src/models/STInvoice.js +16 -16
  199. package/dist/src/models/STInvoice.js.map +1 -1
  200. package/dist/src/models/STPackage.d.ts +1 -1
  201. package/dist/src/models/STPackage.d.ts.map +1 -1
  202. package/dist/src/models/STPackage.js +39 -39
  203. package/dist/src/models/STPackage.js.map +1 -1
  204. package/dist/src/models/STPendingInvoice.d.ts +1 -1
  205. package/dist/src/models/STPendingInvoice.d.ts.map +1 -1
  206. package/dist/src/models/STPendingInvoice.js +11 -11
  207. package/dist/src/models/STPendingInvoice.js.map +1 -1
  208. package/dist/src/models/StripeAccount.d.ts.map +1 -1
  209. package/dist/src/models/StripeAccount.js +13 -13
  210. package/dist/src/models/StripeAccount.js.map +1 -1
  211. package/dist/src/models/StripeCheckoutSession.d.ts +1 -1
  212. package/dist/src/models/StripeCheckoutSession.d.ts.map +1 -1
  213. package/dist/src/models/StripeCheckoutSession.js +7 -7
  214. package/dist/src/models/StripeCheckoutSession.js.map +1 -1
  215. package/dist/src/models/StripePaymentIntent.d.ts +1 -1
  216. package/dist/src/models/StripePaymentIntent.d.ts.map +1 -1
  217. package/dist/src/models/StripePaymentIntent.js +7 -7
  218. package/dist/src/models/StripePaymentIntent.js.map +1 -1
  219. package/dist/src/models/Ticket.d.ts +2 -2
  220. package/dist/src/models/Ticket.d.ts.map +1 -1
  221. package/dist/src/models/Ticket.js +23 -23
  222. package/dist/src/models/Ticket.js.map +1 -1
  223. package/dist/src/models/Token.d.ts +3 -3
  224. package/dist/src/models/Token.d.ts.map +1 -1
  225. package/dist/src/models/Token.js +27 -27
  226. package/dist/src/models/Token.js.map +1 -1
  227. package/dist/src/models/Token.test.js +11 -11
  228. package/dist/src/models/UsedRegisterCode.d.ts +1 -1
  229. package/dist/src/models/UsedRegisterCode.d.ts.map +1 -1
  230. package/dist/src/models/UsedRegisterCode.js +10 -10
  231. package/dist/src/models/UsedRegisterCode.js.map +1 -1
  232. package/dist/src/models/User.d.ts +4 -4
  233. package/dist/src/models/User.d.ts.map +1 -1
  234. package/dist/src/models/User.js +53 -51
  235. package/dist/src/models/User.js.map +1 -1
  236. package/dist/src/models/UserPermissions.d.ts +3 -3
  237. package/dist/src/models/UserPermissions.d.ts.map +1 -1
  238. package/dist/src/models/UserPermissions.js +12 -12
  239. package/dist/src/models/UserPermissions.js.map +1 -1
  240. package/dist/src/models/Webshop.d.ts +1 -1
  241. package/dist/src/models/Webshop.d.ts.map +1 -1
  242. package/dist/src/models/Webshop.js +23 -23
  243. package/dist/src/models/Webshop.js.map +1 -1
  244. package/dist/src/models/WebshopDiscountCode.d.ts +1 -1
  245. package/dist/src/models/WebshopDiscountCode.d.ts.map +1 -1
  246. package/dist/src/models/WebshopDiscountCode.js +16 -16
  247. package/dist/src/models/WebshopDiscountCode.js.map +1 -1
  248. package/dist/src/models/addresses/City.d.ts.map +1 -1
  249. package/dist/src/models/addresses/City.js +9 -9
  250. package/dist/src/models/addresses/City.js.map +1 -1
  251. package/dist/src/models/addresses/PostalCode.d.ts.map +1 -1
  252. package/dist/src/models/addresses/PostalCode.js +11 -11
  253. package/dist/src/models/addresses/PostalCode.js.map +1 -1
  254. package/dist/src/models/addresses/PostalCode.test.js +22 -22
  255. package/dist/src/models/addresses/PostalCode.test.js.map +1 -1
  256. package/dist/src/models/addresses/Province.d.ts.map +1 -1
  257. package/dist/src/models/addresses/Province.js +5 -5
  258. package/dist/src/models/addresses/Province.js.map +1 -1
  259. package/dist/src/models/addresses/Street.d.ts.map +1 -1
  260. package/dist/src/models/addresses/Street.js +6 -6
  261. package/dist/src/models/addresses/Street.js.map +1 -1
  262. package/dist/src/models/index.d.ts +46 -46
  263. package/dist/src/models/index.d.ts.map +1 -1
  264. package/dist/src/models/index.js +0 -1
  265. package/dist/src/models/index.js.map +1 -1
  266. package/dist/src/structures/OrganizationServerMetaData.d.ts.map +1 -1
  267. package/dist/src/structures/OrganizationServerMetaData.js +4 -4
  268. package/dist/src/structures/OrganizationServerMetaData.js.map +1 -1
  269. package/dist/tests/jest.global.setup.d.ts.map +1 -1
  270. package/dist/tests/jest.global.setup.js +15 -13
  271. package/dist/tests/jest.global.setup.js.map +1 -1
  272. package/dist/tests/jest.setup.js +3 -1
  273. package/dist/tests/jest.setup.js.map +1 -1
  274. package/dist/tsconfig.tsbuildinfo +1 -0
  275. package/package.json +3 -3
  276. package/src/factories/AddressFactory.ts +17 -17
  277. package/src/factories/EmergencyContactFactory.ts +30 -31
  278. package/src/factories/GroupFactory.ts +30 -30
  279. package/src/factories/MemberFactory.ts +41 -38
  280. package/src/factories/OrganizationFactory.ts +15 -15
  281. package/src/factories/ParentFactory.ts +24 -24
  282. package/src/factories/RecordFactory.ts +5 -4
  283. package/src/factories/RegisterCodeFactory.ts +7 -7
  284. package/src/factories/RegistrationFactory.ts +16 -16
  285. package/src/factories/RegistrationPeriodFactory.ts +5 -5
  286. package/src/factories/UserFactory.ts +20 -19
  287. package/src/factories/WebshopFactory.ts +14 -14
  288. package/src/helpers/DNSValidator.ts +89 -84
  289. package/src/helpers/EmailBuilder.ts +141 -135
  290. package/src/helpers/GroupBuilder.ts +181 -181
  291. package/src/helpers/Handlebars.ts +57 -54
  292. package/src/helpers/MemberMerger.test.ts +702 -702
  293. package/src/helpers/MemberMerger.ts +83 -77
  294. package/src/helpers/RateLimiter.ts +25 -27
  295. package/src/helpers/SetupStepsUpdater.ts +402 -0
  296. package/src/helpers/WebshopCounter.test.ts +12 -12
  297. package/src/helpers/WebshopCounter.ts +20 -19
  298. package/src/index.ts +20 -19
  299. package/src/migrations/1605262045-import-postcodes.ts +59 -63
  300. package/src/migrations/1605262046-import-postcodes-nl.ts +41 -43
  301. package/src/models/BalanceItem.ts +173 -172
  302. package/src/models/BalanceItemPayment.ts +32 -33
  303. package/src/models/BuckarooPayment.ts +7 -7
  304. package/src/models/CachedOutstandingBalance.ts +98 -99
  305. package/src/models/Document.ts +90 -87
  306. package/src/models/DocumentTemplate.ts +207 -198
  307. package/src/models/Email.ts +198 -200
  308. package/src/models/EmailRecipient.ts +38 -39
  309. package/src/models/EmailTemplate.ts +36 -37
  310. package/src/models/EmailVerificationCode.ts +146 -142
  311. package/src/models/Event.ts +53 -53
  312. package/src/models/Group.ts +136 -123
  313. package/src/models/Image.ts +48 -48
  314. package/src/models/Member.ts +277 -275
  315. package/src/models/MemberPlatformMembership.ts +71 -71
  316. package/src/models/MemberResponsibilityRecord.ts +32 -32
  317. package/src/models/MergedMember.ts +77 -77
  318. package/src/models/MolliePayment.ts +7 -7
  319. package/src/models/MollieToken.ts +131 -126
  320. package/src/models/OneTimeToken.ts +40 -39
  321. package/src/models/Order.ts +379 -372
  322. package/src/models/Organization.ts +332 -325
  323. package/src/models/OrganizationRegistrationPeriod.ts +50 -50
  324. package/src/models/PasswordToken.ts +42 -42
  325. package/src/models/PayconiqPayment.ts +80 -76
  326. package/src/models/Payment.ts +86 -86
  327. package/src/models/Platform.ts +21 -22
  328. package/src/models/RegisterCode.ts +26 -26
  329. package/src/models/Registration.ts +167 -168
  330. package/src/models/RegistrationPeriod.ts +29 -29
  331. package/src/models/STCredit.ts +24 -25
  332. package/src/models/STInvoice.ts +34 -34
  333. package/src/models/STPackage.ts +143 -136
  334. package/src/models/STPendingInvoice.ts +26 -26
  335. package/src/models/StripeAccount.ts +27 -27
  336. package/src/models/StripeCheckoutSession.ts +10 -10
  337. package/src/models/StripePaymentIntent.ts +10 -10
  338. package/src/models/Ticket.ts +51 -52
  339. package/src/models/Token.test.ts +13 -13
  340. package/src/models/Token.ts +64 -63
  341. package/src/models/UsedRegisterCode.ts +20 -21
  342. package/src/models/User.ts +148 -144
  343. package/src/models/UserPermissions.ts +25 -28
  344. package/src/models/Webshop.ts +53 -53
  345. package/src/models/WebshopDiscountCode.ts +33 -33
  346. package/src/models/addresses/City.ts +12 -12
  347. package/src/models/addresses/PostalCode.test.ts +68 -69
  348. package/src/models/addresses/PostalCode.ts +57 -57
  349. package/src/models/addresses/Province.ts +8 -8
  350. package/src/models/addresses/Street.ts +10 -12
  351. package/src/models/index.ts +54 -55
  352. package/src/structures/OrganizationServerMetaData.ts +36 -36
@@ -1,7 +1,7 @@
1
1
  import { column, Database, Model, SQLResultNamespacedRow } from '@simonbackx/simple-database';
2
2
  import { BalanceItemRelation, BalanceItemRelationType, BalanceItemStatus, BalanceItemType, BalanceItemWithPayments, BalanceItemPaymentWithPayment, OrderStatus, Payment as PaymentStruct, RegistrationWithMember } from '@stamhoofd/structures';
3
3
  import { Formatter } from '@stamhoofd/utility';
4
- import { v4 as uuidv4 } from "uuid";
4
+ import { v4 as uuidv4 } from 'uuid';
5
5
 
6
6
  import { EnumDecoder, MapDecoder } from '@simonbackx/simple-encoding';
7
7
  import { Organization, Payment, Webshop } from './';
@@ -12,41 +12,41 @@ import { CachedOutstandingBalance } from './CachedOutstandingBalance';
12
12
  * Keeps track of how much a member/user owes or needs to be reimbursed.
13
13
  */
14
14
  export class BalanceItem extends Model {
15
- static table = "balance_items"
15
+ static table = 'balance_items';
16
16
 
17
17
  @column({
18
- primary: true, type: "string", beforeSave(value) {
18
+ primary: true, type: 'string', beforeSave(value) {
19
19
  return value ?? uuidv4();
20
- }
20
+ },
21
21
  })
22
22
  id!: string;
23
23
 
24
24
  // Receiving organization
25
-
26
- @column({ type: "string" })
27
- organizationId: string
25
+
26
+ @column({ type: 'string' })
27
+ organizationId: string;
28
28
 
29
29
  // Payer: memberId, userId or payingOrganizationId
30
30
 
31
- @column({ type: "string", nullable: true })
31
+ @column({ type: 'string', nullable: true })
32
32
  memberId: string | null = null;
33
33
 
34
- @column({ type: "string", nullable: true })
34
+ @column({ type: 'string', nullable: true })
35
35
  userId: string | null = null;
36
36
 
37
- @column({ type: "string", nullable: true })
37
+ @column({ type: 'string', nullable: true })
38
38
  payingOrganizationId: string | null = null;
39
39
 
40
40
  /**
41
41
  * The registration ID that is linked to this balance item
42
42
  */
43
- @column({ type: "string", nullable: true })
43
+ @column({ type: 'string', nullable: true })
44
44
  registrationId: string | null = null;
45
45
 
46
46
  /**
47
47
  * The order ID that is linked to this balance item
48
48
  */
49
- @column({ type: "string", nullable: true })
49
+ @column({ type: 'string', nullable: true })
50
50
  orderId: string | null = null;
51
51
 
52
52
  /**
@@ -54,66 +54,66 @@ export class BalanceItem extends Model {
54
54
  * -> as soon as this balance item is paid, we'll mark this balance item as pending if it is still hidden
55
55
  * -> allows for a pay back system where one user needs to pay back a different user
56
56
  */
57
- @column({ type: "string", nullable: true })
57
+ @column({ type: 'string', nullable: true })
58
58
  dependingBalanceItemId: string | null = null;
59
59
 
60
- @column({ type: "string" })
61
- type = BalanceItemType.Other
60
+ @column({ type: 'string' })
61
+ type = BalanceItemType.Other;
62
62
 
63
63
  @column({ decoder: new MapDecoder(new EnumDecoder(BalanceItemRelationType), BalanceItemRelation), type: 'json' })
64
- relations: Map<BalanceItemRelationType, BalanceItemRelation> = new Map()
64
+ relations: Map<BalanceItemRelationType, BalanceItemRelation> = new Map();
65
65
 
66
- @column({ type: "string" })
67
- description = "";
66
+ @column({ type: 'string' })
67
+ description = '';
68
68
 
69
69
  /**
70
70
  * Total prices
71
71
  */
72
- @column({ type: "integer" })
73
- amount = 1
72
+ @column({ type: 'integer' })
73
+ amount = 1;
74
74
 
75
75
  /**
76
76
  * Total prices
77
77
  */
78
- @column({ type: "integer" })
78
+ @column({ type: 'integer' })
79
79
  unitPrice: number;
80
80
 
81
81
  /**
82
82
  * Cached value, for optimizations
83
83
  */
84
- @column({ type: "integer" })
85
- pricePaid = 0
84
+ @column({ type: 'integer' })
85
+ pricePaid = 0;
86
86
 
87
87
  /**
88
88
  * Cached value, for optimizations
89
89
  */
90
- @column({ type: "integer" })
91
- pricePending = 0
90
+ @column({ type: 'integer' })
91
+ pricePending = 0;
92
92
 
93
- @column({ type: "string" })
94
- status = BalanceItemStatus.Pending
93
+ @column({ type: 'string' })
94
+ status = BalanceItemStatus.Pending;
95
95
 
96
96
  @column({
97
- type: "datetime", beforeSave(old?: any) {
97
+ type: 'datetime', beforeSave(old?: any) {
98
98
  if (old !== undefined) {
99
99
  return old;
100
100
  }
101
- const date = new Date()
102
- date.setMilliseconds(0)
103
- return date
104
- }
101
+ const date = new Date();
102
+ date.setMilliseconds(0);
103
+ return date;
104
+ },
105
105
  })
106
- createdAt: Date
106
+ createdAt: Date;
107
107
 
108
108
  @column({
109
- type: "datetime", beforeSave() {
110
- const date = new Date()
111
- date.setMilliseconds(0)
112
- return date
109
+ type: 'datetime', beforeSave() {
110
+ const date = new Date();
111
+ date.setMilliseconds(0);
112
+ return date;
113
113
  },
114
- skipUpdate: true
114
+ skipUpdate: true,
115
115
  })
116
- updatedAt: Date
116
+ updatedAt: Date;
117
117
 
118
118
  get price() {
119
119
  return this.unitPrice * this.amount;
@@ -126,10 +126,10 @@ export class BalanceItem extends Model {
126
126
  async markUpdated(payment: Payment, organization: Organization) {
127
127
  // For orders: mark order as changed (so they are refetched in front ends)
128
128
  if (this.orderId) {
129
- const {Order} = await import("./Order");
129
+ const { Order } = await import('./Order');
130
130
  const order = await Order.getByID(this.orderId);
131
131
  if (order) {
132
- await order.paymentChanged(payment, organization)
132
+ await order.paymentChanged(payment, organization);
133
133
  }
134
134
  }
135
135
  }
@@ -137,49 +137,49 @@ export class BalanceItem extends Model {
137
137
  async markPaid(payment: Payment, organization: Organization) {
138
138
  // status and pricePaid changes are handled inside balanceitempayment
139
139
  if (this.dependingBalanceItemId) {
140
- const depending = await BalanceItem.getByID(this.dependingBalanceItemId)
140
+ const depending = await BalanceItem.getByID(this.dependingBalanceItemId);
141
141
  if (depending && depending.status === BalanceItemStatus.Hidden) {
142
- await BalanceItem.reactivateItems([depending])
142
+ await BalanceItem.reactivateItems([depending]);
143
143
  }
144
144
  }
145
145
 
146
146
  // If registration
147
147
  if (this.registrationId) {
148
- const {Registration} = await import("./Registration");
148
+ const { Registration } = await import('./Registration');
149
149
  const registration = await Registration.getByID(this.registrationId);
150
150
 
151
151
  if (registration) {
152
152
  // 1. Mark registration as being valid
153
153
  if (registration.registeredAt === null || registration.deactivatedAt) {
154
- await registration.markValid()
154
+ await registration.markValid();
155
155
 
156
- const {Group} = await import("./Group");
156
+ const { Group } = await import('./Group');
157
157
 
158
158
  // Update group occupancy
159
159
  // TODO: maybe we should schedule this, to prevent doing many updates at once
160
- const group = await Group.getByID(registration.groupId)
160
+ const group = await Group.getByID(registration.groupId);
161
161
  if (group) {
162
- await group.updateOccupancy()
163
- await group.save()
162
+ await group.updateOccupancy();
163
+ await group.save();
164
164
  }
165
- }
165
+ }
166
166
  }
167
167
  }
168
168
 
169
169
  // If order
170
170
  if (this.orderId) {
171
- const {Order} = await import("./Order");
171
+ const { Order } = await import('./Order');
172
172
  const order = await Order.getByID(this.orderId);
173
173
  if (order) {
174
- await order.markPaid(payment, organization)
174
+ await order.markPaid(payment, organization);
175
175
 
176
176
  // Save number in balacance description
177
177
  if (order.number !== null) {
178
- const webshop = await Webshop.getByID(order.webshopId)
178
+ const webshop = await Webshop.getByID(order.webshopId);
179
179
 
180
180
  if (webshop) {
181
- this.description = order.generateBalanceDescription(webshop)
182
- await this.save()
181
+ this.description = order.generateBalanceDescription(webshop);
182
+ await this.save();
183
183
  }
184
184
  }
185
185
  }
@@ -189,10 +189,10 @@ export class BalanceItem extends Model {
189
189
  async undoPaid(payment: Payment, organization: Organization) {
190
190
  // If order
191
191
  if (this.orderId) {
192
- const {Order} = await import("./Order");
192
+ const { Order } = await import('./Order');
193
193
  const order = await Order.getByID(this.orderId);
194
194
  if (order) {
195
- await order.undoPaid(payment, organization)
195
+ await order.undoPaid(payment, organization);
196
196
  }
197
197
  }
198
198
  }
@@ -200,14 +200,14 @@ export class BalanceItem extends Model {
200
200
  async markFailed(payment: Payment, organization: Organization) {
201
201
  // If order
202
202
  if (this.orderId) {
203
- const {Order} = await import("./Order");
203
+ const { Order } = await import('./Order');
204
204
  const order = await Order.getByID(this.orderId);
205
205
  if (order) {
206
- await order.onPaymentFailed(payment, organization)
206
+ await order.onPaymentFailed(payment, organization);
207
207
 
208
208
  if (order.status === OrderStatus.Deleted) {
209
- this.status = BalanceItemStatus.Hidden
210
- await this.save()
209
+ this.status = BalanceItemStatus.Hidden;
210
+ await this.save();
211
211
  }
212
212
  }
213
213
  }
@@ -216,10 +216,10 @@ export class BalanceItem extends Model {
216
216
  async undoFailed(payment: Payment, organization: Organization) {
217
217
  // If order
218
218
  if (this.orderId) {
219
- const {Order} = await import("./Order");
219
+ const { Order } = await import('./Order');
220
220
  const order = await Order.getByID(this.orderId);
221
221
  if (order) {
222
- await order.undoPaymentFailed(payment, organization)
222
+ await order.undoPaymentFailed(payment, organization);
223
223
  }
224
224
  }
225
225
  }
@@ -229,118 +229,117 @@ export class BalanceItem extends Model {
229
229
  }
230
230
 
231
231
  static async deleteItems(items: BalanceItem[]) {
232
- const {balanceItemPayments} = await BalanceItem.loadPayments(items)
232
+ const { balanceItemPayments } = await BalanceItem.loadPayments(items);
233
233
 
234
234
  // todo: in the future we could automatically delete payments that are not needed anymore and weren't paid yet -> to prevent leaving ghost payments
235
235
  // for now, an admin can manually cancel those payments
236
- let needsUpdate = false
236
+ let needsUpdate = false;
237
237
 
238
238
  // Set other items to zero (the balance item payments keep the real price)
239
239
  for (const item of items) {
240
- needsUpdate = true
240
+ needsUpdate = true;
241
241
 
242
242
  // Don't change status of items that are already paid or are partially paid
243
243
  // Not using item.paidPrice, since this is cached
244
- const bip = balanceItemPayments.filter(p => p.balanceItemId == item.id)
244
+ const bip = balanceItemPayments.filter(p => p.balanceItemId == item.id);
245
245
 
246
246
  if (bip.length === 0) {
247
247
  // No payments associated with this item
248
- item.status = BalanceItemStatus.Hidden
249
- item.amount = 0
250
- await item.save()
251
- } else {
252
- item.amount = 0
253
- await item.save()
248
+ item.status = BalanceItemStatus.Hidden;
249
+ item.amount = 0;
250
+ await item.save();
251
+ }
252
+ else {
253
+ item.amount = 0;
254
+ await item.save();
254
255
  }
255
256
  }
256
257
 
257
258
  if (needsUpdate) {
258
- await this.updateOutstanding(items)
259
+ await this.updateOutstanding(items);
259
260
  }
260
261
  }
261
262
 
262
263
  static async reactivateItems(items: BalanceItem[]) {
263
- let needsUpdate = false
264
+ let needsUpdate = false;
264
265
  for (const item of items) {
265
266
  if (item.status === BalanceItemStatus.Hidden) {
266
- item.status = BalanceItemStatus.Pending
267
- needsUpdate = true
268
- await item.save()
267
+ item.status = BalanceItemStatus.Pending;
268
+ needsUpdate = true;
269
+ await item.save();
269
270
  }
270
271
  }
271
272
 
272
273
  if (needsUpdate) {
273
- await this.updateOutstanding(items)
274
+ await this.updateOutstanding(items);
274
275
  }
275
276
  }
276
277
 
277
278
  static async undoForDeletedOrders(orderIds: string[]) {
278
279
  if (orderIds.length === 0) {
279
- return
280
+ return;
280
281
  }
281
- const items = await BalanceItem.where({ orderId: { sign: 'IN', value: orderIds } })
282
- await this.reactivateItems(items)
282
+ const items = await BalanceItem.where({ orderId: { sign: 'IN', value: orderIds } });
283
+ await this.reactivateItems(items);
283
284
  }
284
285
 
285
286
  static async deleteForDeletedOrders(orderIds: string[]) {
286
287
  if (orderIds.length === 0) {
287
- return
288
+ return;
288
289
  }
289
- const items = await BalanceItem.where({ orderId: { sign: 'IN', value: orderIds } })
290
- await this.deleteItems(items)
290
+ const items = await BalanceItem.where({ orderId: { sign: 'IN', value: orderIds } });
291
+ await this.deleteItems(items);
291
292
  }
292
293
 
293
294
  static async deleteForDeletedMember(memberId: string) {
294
- const items = await BalanceItem.where({ memberId })
295
- await this.deleteItems(items)
295
+ const items = await BalanceItem.where({ memberId });
296
+ await this.deleteItems(items);
296
297
  }
297
298
 
298
299
  static async deleteForDeletedRegistration(registrationId: string) {
299
- const items = await BalanceItem.where({ registrationId })
300
- await this.deleteItems(items)
300
+ const items = await BalanceItem.where({ registrationId });
301
+ await this.deleteItems(items);
301
302
  }
302
303
 
303
304
  static async getForRegistration(registrationId: string) {
304
- const items = await BalanceItem.where({ registrationId })
305
+ const items = await BalanceItem.where({ registrationId });
305
306
  return {
306
307
  items,
307
- ...(await this.loadPayments(items))
308
- }
308
+ ...(await this.loadPayments(items)),
309
+ };
309
310
  }
310
311
 
311
312
  static async updateOutstanding(items: BalanceItem[]) {
312
-
313
- console.log("Update outstanding balance for", items.length, "items")
313
+ console.log('Update outstanding balance for', items.length, 'items');
314
314
 
315
315
  await BalanceItem.updatePricePaid(items.map(i => i.id));
316
316
  await BalanceItem.updatePricePending(items.map(i => i.id));
317
-
317
+
318
318
  // Deprecated: the member balances have moved to CachedOutstandingBalance
319
319
  // Update outstanding amount of related members and registrations
320
- const memberIds: string[] = Formatter.uniqueArray(items.map(p => p.memberId).filter(id => id !== null))
321
-
320
+ const memberIds: string[] = Formatter.uniqueArray(items.map(p => p.memberId).filter(id => id !== null));
321
+
322
322
  const Member = (await import('./Member')).Member;
323
- await Member.updateOutstandingBalance(memberIds)
324
-
325
- const {Registration} = await import('./Registration');
323
+ await Member.updateOutstandingBalance(memberIds);
324
+
325
+ const { Registration } = await import('./Registration');
326
326
 
327
- const organizationIds = Formatter.uniqueArray(items.map(p => p.organizationId))
327
+ const organizationIds = Formatter.uniqueArray(items.map(p => p.organizationId));
328
328
  for (const organizationId of organizationIds) {
329
- const filteredItems = items.filter(i => i.organizationId === organizationId)
330
-
331
- const memberIds = Formatter.uniqueArray(filteredItems.map(p => p.memberId).filter(id => id !== null))
332
- await CachedOutstandingBalance.updateForMembers(organizationId, memberIds)
329
+ const filteredItems = items.filter(i => i.organizationId === organizationId);
330
+
331
+ const memberIds = Formatter.uniqueArray(filteredItems.map(p => p.memberId).filter(id => id !== null));
332
+ await CachedOutstandingBalance.updateForMembers(organizationId, memberIds);
333
333
 
334
- const userIds = Formatter.uniqueArray(filteredItems.filter(p => p.memberId === null && p.userId !== null).map(p => p.userId!))
335
- await CachedOutstandingBalance.updateForUsers(organizationId, userIds)
334
+ const userIds = Formatter.uniqueArray(filteredItems.filter(p => p.memberId === null && p.userId !== null).map(p => p.userId!));
335
+ await CachedOutstandingBalance.updateForUsers(organizationId, userIds);
336
336
 
337
- const organizationIds = Formatter.uniqueArray(filteredItems.map(p => p.payingOrganizationId).filter(id => id !== null))
338
- await CachedOutstandingBalance.updateForOrganizations(organizationId, organizationIds)
337
+ const organizationIds = Formatter.uniqueArray(filteredItems.map(p => p.payingOrganizationId).filter(id => id !== null));
338
+ await CachedOutstandingBalance.updateForOrganizations(organizationId, organizationIds);
339
339
 
340
340
  // Deprecated: we'll need to move the outstanding balance of registrations to CachedOutstandingBalance
341
- const registrationIds: string[] = Formatter.uniqueArray(filteredItems.map(p => p.registrationId).filter(id => id !== null))
342
- await Registration.updateOutstandingBalance(registrationIds, organizationId)
343
-
341
+ const registrationIds: string[] = Formatter.uniqueArray(filteredItems.map(p => p.registrationId).filter(id => id !== null));
342
+ await Registration.updateOutstandingBalance(registrationIds, organizationId);
344
343
  }
345
344
  }
346
345
 
@@ -349,21 +348,21 @@ export class BalanceItem extends Model {
349
348
  */
350
349
  static async updatePricePaid(balanceItemIds: string[] | 'all') {
351
350
  if (balanceItemIds !== 'all' && balanceItemIds.length == 0) {
352
- return
351
+ return;
353
352
  }
354
353
 
355
- const params: any[] = []
356
- let firstWhere = ''
357
- let secondWhere = ''
354
+ const params: any[] = [];
355
+ let firstWhere = '';
356
+ let secondWhere = '';
358
357
 
359
358
  if (balanceItemIds !== 'all') {
360
- firstWhere = ` AND balanceItemId IN (?)`
361
- params.push(balanceItemIds)
359
+ firstWhere = ` AND balanceItemId IN (?)`;
360
+ params.push(balanceItemIds);
362
361
 
363
- secondWhere = `WHERE balance_items.id IN (?)`
364
- params.push(balanceItemIds)
362
+ secondWhere = `WHERE balance_items.id IN (?)`;
363
+ params.push(balanceItemIds);
365
364
  }
366
-
365
+
367
366
  // Note: we'll never mark a balance item as 'paid' via the database -> because we need to rigger the markPaid function manually, which will call the appropriate functions
368
367
  // this method will set the balance item to paid once, and only call the handlers once
369
368
  const query = `
@@ -389,7 +388,7 @@ export class BalanceItem extends Model {
389
388
  END)
390
389
  ${secondWhere}`;
391
390
 
392
- await Database.update(query, params)
391
+ await Database.update(query, params);
393
392
  }
394
393
 
395
394
  /**
@@ -397,21 +396,21 @@ export class BalanceItem extends Model {
397
396
  */
398
397
  static async updatePricePending(balanceItemIds: string[] | 'all') {
399
398
  if (balanceItemIds !== 'all' && balanceItemIds.length == 0) {
400
- return
399
+ return;
401
400
  }
402
401
 
403
- const params: any[] = []
404
- let firstWhere = ''
405
- let secondWhere = ''
402
+ const params: any[] = [];
403
+ let firstWhere = '';
404
+ let secondWhere = '';
406
405
 
407
406
  if (balanceItemIds !== 'all') {
408
- firstWhere = ` AND balanceItemId IN (?)`
409
- params.push(balanceItemIds)
407
+ firstWhere = ` AND balanceItemId IN (?)`;
408
+ params.push(balanceItemIds);
410
409
 
411
- secondWhere = `WHERE balance_items.id IN (?)`
412
- params.push(balanceItemIds)
410
+ secondWhere = `WHERE balance_items.id IN (?)`;
411
+ params.push(balanceItemIds);
413
412
  }
414
-
413
+
415
414
  const query = `
416
415
  UPDATE
417
416
  balance_items
@@ -433,60 +432,61 @@ export class BalanceItem extends Model {
433
432
  )
434
433
  ${secondWhere}`;
435
434
 
436
- await Database.update(query, params)
435
+ await Database.update(query, params);
437
436
  }
438
437
 
439
438
  static async loadPayments(items: BalanceItem[]) {
440
439
  if (items.length == 0) {
441
- return {balanceItemPayments: [], payments: []}
440
+ return { balanceItemPayments: [], payments: [] };
442
441
  }
443
442
 
444
443
  // Load balance payment items
445
- const {BalanceItemPayment} = await import('./BalanceItemPayment');
446
- const balanceItemPayments = await BalanceItemPayment.where({ balanceItemId: {sign: 'IN', value: items.map(i => i.id)} })
444
+ const { BalanceItemPayment } = await import('./BalanceItemPayment');
445
+ const balanceItemPayments = await BalanceItemPayment.where({ balanceItemId: { sign: 'IN', value: items.map(i => i.id) } });
447
446
 
448
- const payments = await Payment.getByIDs(...balanceItemPayments.map(p => p.paymentId))
447
+ const payments = await Payment.getByIDs(...balanceItemPayments.map(p => p.paymentId));
449
448
 
450
- return {payments, balanceItemPayments}
449
+ return { payments, balanceItemPayments };
451
450
  }
452
451
 
453
452
  static async getStructureWithPayments(items: BalanceItem[]): Promise<BalanceItemWithPayments[]> {
454
453
  if (items.length == 0) {
455
- return []
454
+ return [];
456
455
  }
457
456
 
458
- const {payments, balanceItemPayments} = await BalanceItem.loadPayments(items)
459
-
460
- return items.map(item => {
461
- const thisBalanceItemPayments = balanceItemPayments.filter(p => p.balanceItemId === item.id)
457
+ const { payments, balanceItemPayments } = await BalanceItem.loadPayments(items);
458
+
459
+ return items.map((item) => {
460
+ const thisBalanceItemPayments = balanceItemPayments.filter(p => p.balanceItemId === item.id);
462
461
 
463
462
  return BalanceItemWithPayments.create({
464
463
  ...item,
465
- payments: thisBalanceItemPayments.map(p => {
466
- const payment = payments.find(pp => pp.id === p.paymentId)!
464
+ payments: thisBalanceItemPayments.map((p) => {
465
+ const payment = payments.find(pp => pp.id === p.paymentId)!;
467
466
  return BalanceItemPaymentWithPayment.create({
468
467
  ...p,
469
- payment: PaymentStruct.create(payment)
470
- })
471
- })
472
- })
473
- })
468
+ payment: PaymentStruct.create(payment),
469
+ });
470
+ }),
471
+ });
472
+ });
474
473
  }
475
474
 
476
- static async balanceItemsForUsersAndMembers(organizationId: string|null, userIds: string[], memberIds: string[]): Promise<BalanceItem[]> {
475
+ static async balanceItemsForUsersAndMembers(organizationId: string | null, userIds: string[], memberIds: string[]): Promise<BalanceItem[]> {
477
476
  if (memberIds.length == 0 && userIds.length == 0) {
478
- return []
477
+ return [];
479
478
  }
480
-
479
+
481
480
  const params: any[] = [];
482
481
  const where: string[] = [];
483
482
 
484
483
  if (memberIds.length) {
485
484
  if (memberIds.length == 1) {
486
- where.push(`memberId = ?`)
485
+ where.push(`memberId = ?`);
487
486
  params.push(memberIds[0]);
488
- } else {
489
- where.push(`memberId IN (?)`)
487
+ }
488
+ else {
489
+ where.push(`memberId IN (?)`);
490
490
  params.push(memberIds);
491
491
  }
492
492
  }
@@ -495,10 +495,11 @@ export class BalanceItem extends Model {
495
495
  // Better if we do it in code here
496
496
  if (userIds.length) {
497
497
  if (userIds.length == 1) {
498
- where.push('userId = ?')
498
+ where.push('userId = ?');
499
499
  params.push(userIds[0]);
500
- } else {
501
- where.push('userId IN (?)')
500
+ }
501
+ else {
502
+ where.push('userId IN (?)');
502
503
  params.push(userIds);
503
504
  }
504
505
  }
@@ -506,28 +507,28 @@ export class BalanceItem extends Model {
506
507
  const requiredWhere: string[] = [];
507
508
 
508
509
  if (organizationId) {
509
- requiredWhere.push('organizationId = ?')
510
+ requiredWhere.push('organizationId = ?');
510
511
  params.push(organizationId);
511
512
  }
512
-
513
- const query = `SELECT ${BalanceItem.getDefaultSelect()} FROM ${BalanceItem.table} WHERE (${where.join(" OR ")}) ${requiredWhere.length ? (' AND ' + requiredWhere.join(' AND ')) : ''} AND ${BalanceItem.table}.status != ?`;
513
+
514
+ const query = `SELECT ${BalanceItem.getDefaultSelect()} FROM ${BalanceItem.table} WHERE (${where.join(' OR ')}) ${requiredWhere.length ? (' AND ' + requiredWhere.join(' AND ')) : ''} AND ${BalanceItem.table}.status != ?`;
514
515
  params.push(BalanceItemStatus.Hidden);
515
-
516
+
516
517
  const [rows] = await Database.select(query, params);
517
518
  const balanceItems = BalanceItem.fromRows(rows, BalanceItem.table);
518
519
 
519
520
  // Filter out items of other members
520
521
  if (memberIds.length) {
521
- return balanceItems.filter(b => !b.memberId || memberIds.includes(b.memberId))
522
+ return balanceItems.filter(b => !b.memberId || memberIds.includes(b.memberId));
522
523
  }
523
524
  return balanceItems;
524
525
  }
525
526
 
526
527
  static async balanceItemsForOrganization(organizationId: string): Promise<BalanceItem[]> {
527
528
  return await BalanceItem.select()
528
- .where('payingOrganizationId', organizationId)
529
- .whereNot('status', BalanceItemStatus.Hidden)
530
- .fetch();
529
+ .where('payingOrganizationId', organizationId)
530
+ .whereNot('status', BalanceItemStatus.Hidden)
531
+ .fetch();
531
532
  }
532
533
 
533
534
  /**
@@ -535,16 +536,16 @@ export class BalanceItem extends Model {
535
536
  */
536
537
  static select() {
537
538
  const transformer = (row: SQLResultNamespacedRow): BalanceItem => {
538
- const d = (this as typeof BalanceItem & typeof Model).fromRow(row[this.table] as any) as BalanceItem|undefined
539
+ const d = (this as typeof BalanceItem & typeof Model).fromRow(row[this.table] as any) as BalanceItem | undefined;
539
540
 
540
541
  if (!d) {
541
- throw new Error("EmailTemplate not found")
542
+ throw new Error('EmailTemplate not found');
542
543
  }
543
544
 
544
545
  return d;
545
- }
546
-
547
- const select = new SQLSelect(transformer, SQL.wildcard())
548
- return select.from(SQL.table(this.table))
546
+ };
547
+
548
+ const select = new SQLSelect(transformer, SQL.wildcard());
549
+ return select.from(SQL.table(this.table));
549
550
  }
550
551
  }