@stamhoofd/models 2.64.0 → 2.65.1

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 (279) hide show
  1. package/dist/src/helpers/EmailBuilder.d.ts +6 -1
  2. package/dist/src/helpers/EmailBuilder.d.ts.map +1 -1
  3. package/dist/src/helpers/EmailBuilder.js +60 -20
  4. package/dist/src/helpers/EmailBuilder.js.map +1 -1
  5. package/dist/src/helpers/MemberMerger.d.ts.map +1 -1
  6. package/dist/src/helpers/MemberMerger.js +1 -2
  7. package/dist/src/helpers/MemberMerger.js.map +1 -1
  8. package/dist/src/migrations/1605262045-import-postcodes.d.ts +2 -2
  9. package/dist/src/migrations/1605262045-import-postcodes.js +9 -9
  10. package/dist/src/migrations/1735573520-emails-email-type.sql +2 -0
  11. package/dist/src/migrations/1735573521-email-recipients-email-type.sql +4 -0
  12. package/dist/src/migrations/1735573522-emails-indexes.sql +3 -0
  13. package/dist/src/migrations/1735982691-cached-balance-email-reminder-counts.sql +4 -0
  14. package/dist/src/migrations/1735994471-default-email-templates.sql +5 -0
  15. package/dist/src/models/AuditLog.d.ts +2 -7
  16. package/dist/src/models/AuditLog.d.ts.map +1 -1
  17. package/dist/src/models/AuditLog.js +1 -15
  18. package/dist/src/models/AuditLog.js.map +1 -1
  19. package/dist/src/models/BalanceItem.d.ts +7 -11
  20. package/dist/src/models/BalanceItem.d.ts.map +1 -1
  21. package/dist/src/models/BalanceItem.js +20 -22
  22. package/dist/src/models/BalanceItem.js.map +1 -1
  23. package/dist/src/models/BalanceItemPayment.d.ts +3 -7
  24. package/dist/src/models/BalanceItemPayment.d.ts.map +1 -1
  25. package/dist/src/models/BalanceItemPayment.js +1 -15
  26. package/dist/src/models/BalanceItemPayment.js.map +1 -1
  27. package/dist/src/models/BuckarooPayment.d.ts +2 -2
  28. package/dist/src/models/BuckarooPayment.d.ts.map +1 -1
  29. package/dist/src/models/BuckarooPayment.js +2 -1
  30. package/dist/src/models/BuckarooPayment.js.map +1 -1
  31. package/dist/src/models/CachedBalance.d.ts +7 -9
  32. package/dist/src/models/CachedBalance.d.ts.map +1 -1
  33. package/dist/src/models/CachedBalance.js +61 -22
  34. package/dist/src/models/CachedBalance.js.map +1 -1
  35. package/dist/src/models/Document.d.ts +3 -3
  36. package/dist/src/models/Document.d.ts.map +1 -1
  37. package/dist/src/models/Document.js +2 -1
  38. package/dist/src/models/Document.js.map +1 -1
  39. package/dist/src/models/DocumentTemplate.d.ts +2 -2
  40. package/dist/src/models/DocumentTemplate.d.ts.map +1 -1
  41. package/dist/src/models/DocumentTemplate.js +2 -1
  42. package/dist/src/models/DocumentTemplate.js.map +1 -1
  43. package/dist/src/models/Email.d.ts +10 -4
  44. package/dist/src/models/Email.d.ts.map +1 -1
  45. package/dist/src/models/Email.js +68 -25
  46. package/dist/src/models/Email.js.map +1 -1
  47. package/dist/src/models/EmailRecipient.d.ts +14 -8
  48. package/dist/src/models/EmailRecipient.d.ts.map +1 -1
  49. package/dist/src/models/EmailRecipient.js +19 -14
  50. package/dist/src/models/EmailRecipient.js.map +1 -1
  51. package/dist/src/models/EmailTemplate.d.ts +2 -7
  52. package/dist/src/models/EmailTemplate.d.ts.map +1 -1
  53. package/dist/src/models/EmailTemplate.js +1 -15
  54. package/dist/src/models/EmailTemplate.js.map +1 -1
  55. package/dist/src/models/EmailVerificationCode.d.ts +2 -2
  56. package/dist/src/models/EmailVerificationCode.d.ts.map +1 -1
  57. package/dist/src/models/EmailVerificationCode.js +2 -1
  58. package/dist/src/models/EmailVerificationCode.js.map +1 -1
  59. package/dist/src/models/Event.d.ts +2 -2
  60. package/dist/src/models/Event.d.ts.map +1 -1
  61. package/dist/src/models/Event.js +2 -1
  62. package/dist/src/models/Event.js.map +1 -1
  63. package/dist/src/models/Group.d.ts +2 -7
  64. package/dist/src/models/Group.d.ts.map +1 -1
  65. package/dist/src/models/Group.js +1 -17
  66. package/dist/src/models/Group.js.map +1 -1
  67. package/dist/src/models/Image.d.ts +2 -2
  68. package/dist/src/models/Image.d.ts.map +1 -1
  69. package/dist/src/models/Image.js +2 -1
  70. package/dist/src/models/Image.js.map +1 -1
  71. package/dist/src/models/Member.d.ts +3 -2
  72. package/dist/src/models/Member.d.ts.map +1 -1
  73. package/dist/src/models/Member.js +1 -1
  74. package/dist/src/models/Member.js.map +1 -1
  75. package/dist/src/models/MemberPlatformMembership.d.ts +2 -7
  76. package/dist/src/models/MemberPlatformMembership.d.ts.map +1 -1
  77. package/dist/src/models/MemberPlatformMembership.js +1 -15
  78. package/dist/src/models/MemberPlatformMembership.js.map +1 -1
  79. package/dist/src/models/MemberResponsibilityRecord.d.ts +2 -7
  80. package/dist/src/models/MemberResponsibilityRecord.d.ts.map +1 -1
  81. package/dist/src/models/MemberResponsibilityRecord.js +1 -15
  82. package/dist/src/models/MemberResponsibilityRecord.js.map +1 -1
  83. package/dist/src/models/MemberUser.d.ts +8 -0
  84. package/dist/src/models/MemberUser.d.ts.map +1 -0
  85. package/dist/src/models/MemberUser.js +26 -0
  86. package/dist/src/models/MemberUser.js.map +1 -0
  87. package/dist/src/models/MergedMember.d.ts +2 -2
  88. package/dist/src/models/MergedMember.d.ts.map +1 -1
  89. package/dist/src/models/MergedMember.js +2 -1
  90. package/dist/src/models/MergedMember.js.map +1 -1
  91. package/dist/src/models/MolliePayment.d.ts +2 -2
  92. package/dist/src/models/MolliePayment.d.ts.map +1 -1
  93. package/dist/src/models/MolliePayment.js +2 -1
  94. package/dist/src/models/MolliePayment.js.map +1 -1
  95. package/dist/src/models/MollieToken.d.ts +2 -2
  96. package/dist/src/models/MollieToken.d.ts.map +1 -1
  97. package/dist/src/models/MollieToken.js +2 -1
  98. package/dist/src/models/MollieToken.js.map +1 -1
  99. package/dist/src/models/OneTimeToken.d.ts +2 -2
  100. package/dist/src/models/OneTimeToken.d.ts.map +1 -1
  101. package/dist/src/models/OneTimeToken.js +2 -1
  102. package/dist/src/models/OneTimeToken.js.map +1 -1
  103. package/dist/src/models/Order.d.ts +3 -2
  104. package/dist/src/models/Order.d.ts.map +1 -1
  105. package/dist/src/models/Order.js +2 -1
  106. package/dist/src/models/Order.js.map +1 -1
  107. package/dist/src/models/Organization.d.ts +2 -2
  108. package/dist/src/models/Organization.d.ts.map +1 -1
  109. package/dist/src/models/Organization.js +2 -1
  110. package/dist/src/models/Organization.js.map +1 -1
  111. package/dist/src/models/OrganizationRegistrationPeriod.d.ts +2 -2
  112. package/dist/src/models/OrganizationRegistrationPeriod.d.ts.map +1 -1
  113. package/dist/src/models/OrganizationRegistrationPeriod.js +2 -1
  114. package/dist/src/models/OrganizationRegistrationPeriod.js.map +1 -1
  115. package/dist/src/models/PasswordToken.d.ts +3 -2
  116. package/dist/src/models/PasswordToken.d.ts.map +1 -1
  117. package/dist/src/models/PasswordToken.js +2 -1
  118. package/dist/src/models/PasswordToken.js.map +1 -1
  119. package/dist/src/models/PayconiqPayment.d.ts +2 -2
  120. package/dist/src/models/PayconiqPayment.d.ts.map +1 -1
  121. package/dist/src/models/PayconiqPayment.js +2 -1
  122. package/dist/src/models/PayconiqPayment.js.map +1 -1
  123. package/dist/src/models/Payment.d.ts +2 -7
  124. package/dist/src/models/Payment.d.ts.map +1 -1
  125. package/dist/src/models/Payment.js +1 -15
  126. package/dist/src/models/Payment.js.map +1 -1
  127. package/dist/src/models/Platform.d.ts +3 -3
  128. package/dist/src/models/Platform.d.ts.map +1 -1
  129. package/dist/src/models/Platform.js +2 -1
  130. package/dist/src/models/Platform.js.map +1 -1
  131. package/dist/src/models/RegisterCode.d.ts +2 -2
  132. package/dist/src/models/RegisterCode.d.ts.map +1 -1
  133. package/dist/src/models/RegisterCode.js +2 -1
  134. package/dist/src/models/RegisterCode.js.map +1 -1
  135. package/dist/src/models/Registration.d.ts +3 -2
  136. package/dist/src/models/Registration.d.ts.map +1 -1
  137. package/dist/src/models/Registration.js +2 -27
  138. package/dist/src/models/Registration.js.map +1 -1
  139. package/dist/src/models/RegistrationPeriod.d.ts +2 -7
  140. package/dist/src/models/RegistrationPeriod.d.ts.map +1 -1
  141. package/dist/src/models/RegistrationPeriod.js +1 -15
  142. package/dist/src/models/RegistrationPeriod.js.map +1 -1
  143. package/dist/src/models/STCredit.d.ts +2 -2
  144. package/dist/src/models/STCredit.d.ts.map +1 -1
  145. package/dist/src/models/STCredit.js +2 -1
  146. package/dist/src/models/STCredit.js.map +1 -1
  147. package/dist/src/models/STInvoice.d.ts +3 -2
  148. package/dist/src/models/STInvoice.d.ts.map +1 -1
  149. package/dist/src/models/STInvoice.js +2 -1
  150. package/dist/src/models/STInvoice.js.map +1 -1
  151. package/dist/src/models/STPackage.d.ts +2 -2
  152. package/dist/src/models/STPackage.d.ts.map +1 -1
  153. package/dist/src/models/STPackage.js +2 -1
  154. package/dist/src/models/STPackage.js.map +1 -1
  155. package/dist/src/models/STPendingInvoice.d.ts +3 -2
  156. package/dist/src/models/STPendingInvoice.d.ts.map +1 -1
  157. package/dist/src/models/STPendingInvoice.js +2 -1
  158. package/dist/src/models/STPendingInvoice.js.map +1 -1
  159. package/dist/src/models/StripeAccount.d.ts +2 -2
  160. package/dist/src/models/StripeAccount.d.ts.map +1 -1
  161. package/dist/src/models/StripeAccount.js +2 -1
  162. package/dist/src/models/StripeAccount.js.map +1 -1
  163. package/dist/src/models/StripeCheckoutSession.d.ts +2 -2
  164. package/dist/src/models/StripeCheckoutSession.d.ts.map +1 -1
  165. package/dist/src/models/StripeCheckoutSession.js +2 -1
  166. package/dist/src/models/StripeCheckoutSession.js.map +1 -1
  167. package/dist/src/models/StripePaymentIntent.d.ts +2 -2
  168. package/dist/src/models/StripePaymentIntent.d.ts.map +1 -1
  169. package/dist/src/models/StripePaymentIntent.js +2 -1
  170. package/dist/src/models/StripePaymentIntent.js.map +1 -1
  171. package/dist/src/models/Ticket.d.ts +3 -2
  172. package/dist/src/models/Ticket.d.ts.map +1 -1
  173. package/dist/src/models/Ticket.js +2 -1
  174. package/dist/src/models/Ticket.js.map +1 -1
  175. package/dist/src/models/Token.d.ts +3 -2
  176. package/dist/src/models/Token.d.ts.map +1 -1
  177. package/dist/src/models/Token.js +2 -1
  178. package/dist/src/models/Token.js.map +1 -1
  179. package/dist/src/models/UsedRegisterCode.d.ts +2 -2
  180. package/dist/src/models/UsedRegisterCode.d.ts.map +1 -1
  181. package/dist/src/models/UsedRegisterCode.js +2 -1
  182. package/dist/src/models/UsedRegisterCode.js.map +1 -1
  183. package/dist/src/models/User.d.ts +7 -2
  184. package/dist/src/models/User.d.ts.map +1 -1
  185. package/dist/src/models/User.js +27 -4
  186. package/dist/src/models/User.js.map +1 -1
  187. package/dist/src/models/UserPermissions.d.ts +3 -2
  188. package/dist/src/models/UserPermissions.d.ts.map +1 -1
  189. package/dist/src/models/UserPermissions.js +2 -1
  190. package/dist/src/models/UserPermissions.js.map +1 -1
  191. package/dist/src/models/Webshop.d.ts +3 -2
  192. package/dist/src/models/Webshop.d.ts.map +1 -1
  193. package/dist/src/models/Webshop.js +2 -1
  194. package/dist/src/models/Webshop.js.map +1 -1
  195. package/dist/src/models/WebshopDiscountCode.d.ts +2 -2
  196. package/dist/src/models/WebshopDiscountCode.d.ts.map +1 -1
  197. package/dist/src/models/WebshopDiscountCode.js +2 -1
  198. package/dist/src/models/WebshopDiscountCode.js.map +1 -1
  199. package/dist/src/models/addresses/City.d.ts +3 -2
  200. package/dist/src/models/addresses/City.d.ts.map +1 -1
  201. package/dist/src/models/addresses/City.js +2 -1
  202. package/dist/src/models/addresses/City.js.map +1 -1
  203. package/dist/src/models/addresses/PostalCode.d.ts +3 -2
  204. package/dist/src/models/addresses/PostalCode.d.ts.map +1 -1
  205. package/dist/src/models/addresses/PostalCode.js +2 -1
  206. package/dist/src/models/addresses/PostalCode.js.map +1 -1
  207. package/dist/src/models/addresses/Province.d.ts +2 -2
  208. package/dist/src/models/addresses/Province.d.ts.map +1 -1
  209. package/dist/src/models/addresses/Province.js +2 -1
  210. package/dist/src/models/addresses/Province.js.map +1 -1
  211. package/dist/src/models/addresses/Street.d.ts +3 -2
  212. package/dist/src/models/addresses/Street.d.ts.map +1 -1
  213. package/dist/src/models/addresses/Street.js +2 -1
  214. package/dist/src/models/addresses/Street.js.map +1 -1
  215. package/dist/src/models/index.d.ts +1 -0
  216. package/dist/src/models/index.d.ts.map +1 -1
  217. package/dist/src/models/index.js +1 -0
  218. package/dist/src/models/index.js.map +1 -1
  219. package/dist/tsconfig.tsbuildinfo +1 -1
  220. package/package.json +2 -2
  221. package/src/helpers/EmailBuilder.ts +82 -27
  222. package/src/helpers/MemberMerger.ts +2 -3
  223. package/src/migrations/1605262045-import-postcodes.ts +4 -5
  224. package/src/migrations/1735573520-emails-email-type.sql +2 -0
  225. package/src/migrations/1735573521-email-recipients-email-type.sql +4 -0
  226. package/src/migrations/1735573522-emails-indexes.sql +3 -0
  227. package/src/migrations/1735982691-cached-balance-email-reminder-counts.sql +4 -0
  228. package/src/migrations/1735994471-default-email-templates.sql +5 -0
  229. package/src/models/AuditLog.ts +3 -21
  230. package/src/models/BalanceItem.ts +27 -30
  231. package/src/models/BalanceItemPayment.ts +3 -21
  232. package/src/models/BuckarooPayment.ts +3 -2
  233. package/src/models/CachedBalance.ts +82 -27
  234. package/src/models/Document.ts +4 -3
  235. package/src/models/DocumentTemplate.ts +4 -3
  236. package/src/models/Email.ts +80 -32
  237. package/src/models/EmailRecipient.ts +20 -20
  238. package/src/models/EmailTemplate.ts +3 -21
  239. package/src/models/EmailVerificationCode.ts +3 -2
  240. package/src/models/Event.ts +3 -2
  241. package/src/models/Group.ts +4 -23
  242. package/src/models/Image.ts +3 -2
  243. package/src/models/Member.ts +4 -4
  244. package/src/models/MemberPlatformMembership.ts +3 -21
  245. package/src/models/MemberResponsibilityRecord.ts +3 -21
  246. package/src/models/MemberUser.ts +18 -0
  247. package/src/models/MergedMember.ts +3 -2
  248. package/src/models/MolliePayment.ts +3 -2
  249. package/src/models/MollieToken.ts +3 -2
  250. package/src/models/OneTimeToken.ts +3 -2
  251. package/src/models/Order.ts +3 -2
  252. package/src/models/Organization.ts +3 -2
  253. package/src/models/OrganizationRegistrationPeriod.ts +3 -2
  254. package/src/models/PasswordToken.ts +3 -2
  255. package/src/models/PayconiqPayment.ts +3 -2
  256. package/src/models/Payment.ts +3 -21
  257. package/src/models/Platform.ts +4 -3
  258. package/src/models/RegisterCode.ts +3 -2
  259. package/src/models/Registration.ts +3 -28
  260. package/src/models/RegistrationPeriod.ts +3 -21
  261. package/src/models/STCredit.ts +3 -2
  262. package/src/models/STInvoice.ts +3 -2
  263. package/src/models/STPackage.ts +3 -2
  264. package/src/models/STPendingInvoice.ts +3 -2
  265. package/src/models/StripeAccount.ts +3 -2
  266. package/src/models/StripeCheckoutSession.ts +3 -2
  267. package/src/models/StripePaymentIntent.ts +3 -2
  268. package/src/models/Ticket.ts +3 -2
  269. package/src/models/Token.ts +3 -2
  270. package/src/models/UsedRegisterCode.ts +3 -2
  271. package/src/models/User.ts +31 -3
  272. package/src/models/UserPermissions.ts +3 -2
  273. package/src/models/Webshop.ts +3 -2
  274. package/src/models/WebshopDiscountCode.ts +3 -2
  275. package/src/models/addresses/City.ts +3 -2
  276. package/src/models/addresses/PostalCode.ts +3 -2
  277. package/src/models/addresses/Province.ts +3 -2
  278. package/src/models/addresses/Street.ts +3 -2
  279. package/src/models/index.ts +1 -0
@@ -1,10 +1,11 @@
1
- import { column, Model } from '@simonbackx/simple-database';
1
+ import { column } from '@simonbackx/simple-database';
2
+ import { QueryableModel } from '@stamhoofd/sql';
2
3
  import { Group as GroupStruct, OrganizationRegistrationPeriodSettings, OrganizationRegistrationPeriod as OrganizationRegistrationPeriodStruct, SetupSteps } from '@stamhoofd/structures';
3
4
  import { Formatter } from '@stamhoofd/utility';
4
5
  import { v4 as uuidv4 } from 'uuid';
5
6
  import { Group, RegistrationPeriod } from '.';
6
7
 
7
- export class OrganizationRegistrationPeriod extends Model {
8
+ export class OrganizationRegistrationPeriod extends QueryableModel {
8
9
  static table = 'organization_registration_periods';
9
10
 
10
11
  @column({
@@ -1,5 +1,6 @@
1
- import { column, Database, ManyToOneRelation, Model } from '@simonbackx/simple-database';
1
+ import { column, Database, ManyToOneRelation } from '@simonbackx/simple-database';
2
2
  import { I18n } from '@stamhoofd/backend-i18n';
3
+ import { QueryableModel } from '@stamhoofd/sql';
3
4
  import basex from 'base-x';
4
5
  import crypto from 'crypto';
5
6
 
@@ -21,7 +22,7 @@ async function randomBytes(size: number): Promise<Buffer> {
21
22
  });
22
23
  }
23
24
 
24
- export class PasswordToken extends Model {
25
+ export class PasswordToken extends QueryableModel {
25
26
  static table = 'password_tokens';
26
27
 
27
28
  // Columns
@@ -1,5 +1,6 @@
1
- import { column, Model } from '@simonbackx/simple-database';
1
+ import { column } from '@simonbackx/simple-database';
2
2
  import { SimpleError } from '@simonbackx/simple-errors';
3
+ import { QueryableModel } from '@stamhoofd/sql';
3
4
  import { PayconiqAccount, PaymentStatus, Version } from '@stamhoofd/structures';
4
5
  import { IncomingMessage } from 'http';
5
6
  import https from 'https';
@@ -7,7 +8,7 @@ import { v4 as uuidv4 } from 'uuid';
7
8
 
8
9
  import { Organization, Payment } from './';
9
10
 
10
- export class PayconiqPayment extends Model {
11
+ export class PayconiqPayment extends QueryableModel {
11
12
  static table = 'payconiq_payments';
12
13
 
13
14
  @column({
@@ -1,12 +1,12 @@
1
- import { column, Model, SQLResultNamespacedRow } from '@simonbackx/simple-database';
1
+ import { column } from '@simonbackx/simple-database';
2
2
  import { BalanceItemDetailed, BalanceItemPaymentDetailed, PaymentCustomer, PaymentGeneral, PaymentMethod, PaymentProvider, PaymentStatus, Settlement, TransferSettings, BaseOrganization, PaymentType } from '@stamhoofd/structures';
3
3
  import { Formatter } from '@stamhoofd/utility';
4
4
  import { v4 as uuidv4 } from 'uuid';
5
5
 
6
6
  import { Organization } from './';
7
- import { SQL, SQLSelect } from '@stamhoofd/sql';
7
+ import { QueryableModel } from '@stamhoofd/sql';
8
8
 
9
- export class Payment extends Model {
9
+ export class Payment extends QueryableModel {
10
10
  static table = 'payments';
11
11
 
12
12
  @column({
@@ -245,22 +245,4 @@ export class Payment extends Model {
245
245
 
246
246
  return { registrations, orders };
247
247
  }
248
-
249
- /**
250
- * Experimental: needs to move to library
251
- */
252
- static select() {
253
- const transformer = (row: SQLResultNamespacedRow): Payment => {
254
- const d = (this as typeof Payment & typeof Model).fromRow(row[this.table] as any) as Payment | undefined;
255
-
256
- if (!d) {
257
- throw new Error('EmailTemplate not found');
258
- }
259
-
260
- return d;
261
- };
262
-
263
- const select = new SQLSelect(transformer, SQL.wildcard(this.table));
264
- return select.from(SQL.table(this.table));
265
- }
266
248
  }
@@ -1,10 +1,11 @@
1
- import { column, Model } from '@simonbackx/simple-database';
1
+ import { column } from '@simonbackx/simple-database';
2
2
  import { QueueHandler } from '@stamhoofd/queues';
3
- import { Platform as PlatformStruct, PlatformConfig, PlatformPrivateConfig } from '@stamhoofd/structures';
3
+ import { QueryableModel } from '@stamhoofd/sql';
4
+ import { PlatformConfig, PlatformPrivateConfig, Platform as PlatformStruct } from '@stamhoofd/structures';
4
5
  import { v4 as uuidv4 } from 'uuid';
5
6
  import { RegistrationPeriod } from './RegistrationPeriod';
6
7
 
7
- export class Platform extends Model {
8
+ export class Platform extends QueryableModel {
8
9
  static table = 'platform';
9
10
 
10
11
  @column({
@@ -1,4 +1,5 @@
1
- import { column, Model } from '@simonbackx/simple-database';
1
+ import { column } from '@simonbackx/simple-database';
2
+ import { QueryableModel } from '@stamhoofd/sql';
2
3
  import basex from 'base-x';
3
4
  import crypto from 'crypto';
4
5
 
@@ -17,7 +18,7 @@ async function randomBytes(size: number): Promise<Buffer> {
17
18
  });
18
19
  }
19
20
 
20
- export class RegisterCode extends Model {
21
+ export class RegisterCode extends QueryableModel {
21
22
  static table = 'register_codes';
22
23
 
23
24
  @column({ type: 'string', primary: true })
@@ -1,13 +1,14 @@
1
- import { column, Database, ManyToOneRelation, Model } from '@simonbackx/simple-database';
1
+ import { column, Database, ManyToOneRelation } from '@simonbackx/simple-database';
2
2
  import { EmailTemplateType, GroupPrice, PaymentMethod, PaymentMethodHelper, Recipient, RecordAnswer, RecordAnswerDecoder, RegisterItemOption, Registration as RegistrationStructure, Replacement, StockReservation } from '@stamhoofd/structures';
3
3
  import { Formatter } from '@stamhoofd/utility';
4
4
  import { v4 as uuidv4 } from 'uuid';
5
5
 
6
6
  import { ArrayDecoder, MapDecoder, StringDecoder } from '@simonbackx/simple-encoding';
7
+ import { QueryableModel } from '@stamhoofd/sql';
7
8
  import { sendEmailTemplate } from '../helpers/EmailBuilder';
8
9
  import { Group, Organization, User } from './';
9
10
 
10
- export class Registration extends Model {
11
+ export class Registration extends QueryableModel {
11
12
  static table = 'registrations';
12
13
 
13
14
  @column({
@@ -179,14 +180,6 @@ export class Registration extends Model {
179
180
  email: user.email,
180
181
  userId: user.id,
181
182
  replacements: [
182
- Replacement.create({
183
- token: 'firstName',
184
- value: member.details.firstName,
185
- }),
186
- Replacement.create({
187
- token: 'lastName',
188
- value: member.details.lastName,
189
- }),
190
183
  Replacement.create({
191
184
  token: 'firstNameMember',
192
185
  value: member.details.firstName,
@@ -195,27 +188,14 @@ export class Registration extends Model {
195
188
  token: 'lastNameMember',
196
189
  value: member.details.lastName,
197
190
  }),
198
- Replacement.create({
199
- token: 'email',
200
- value: user.email,
201
- }),
202
191
  Replacement.create({
203
192
  token: 'registerUrl',
204
193
  value: 'https://' + organization.getHost(),
205
194
  }),
206
- Replacement.create({
207
- token: 'organizationName',
208
- value: organization.name,
209
- }),
210
195
  Replacement.create({
211
196
  token: 'groupName',
212
197
  value: group.settings.name,
213
198
  }),
214
- Replacement.create({
215
- token: 'loginDetails',
216
- value: '',
217
- html: user.hasAccount() ? `<p class="description"><em>Je kan op het ledenportaal inloggen met <strong>${Formatter.escapeHtml(user.email)}</strong></em></p>` : `<p class="description"><em>Je kan op het ledenportaal een nieuw account aanmaken met het e-mailadres <strong>${Formatter.escapeHtml(user.email)}</strong>, dan krijg je automatisch toegang tot alle bestaande gegevens.</em></p>`,
218
- }),
219
199
  ],
220
200
  }));
221
201
  }
@@ -310,11 +290,6 @@ export class Registration extends Model {
310
290
  token: 'organizationName',
311
291
  value: organization.name,
312
292
  }),
313
- Replacement.create({
314
- token: 'loginDetails',
315
- value: '',
316
- html: user.hasAccount() ? `<p class="description"><em>Je kan op het ledenportaal inloggen met <strong>${Formatter.escapeHtml(user.email)}</strong></em></p>` : `<p class="description"><em>Je kan op het ledenportaal een nieuw account aanmaken met het e-mailadres <strong>${Formatter.escapeHtml(user.email)}</strong>, dan krijg je automatisch toegang tot alle bestaande gegevens.</em></p>`,
317
- }),
318
293
  ],
319
294
  }),
320
295
  ];
@@ -1,9 +1,9 @@
1
- import { column, Model, SQLResultNamespacedRow } from '@simonbackx/simple-database';
2
- import { SQL, SQLSelect, SQLWhereSign } from '@stamhoofd/sql';
1
+ import { column } from '@simonbackx/simple-database';
2
+ import { QueryableModel, SQL, SQLWhereSign } from '@stamhoofd/sql';
3
3
  import { RegistrationPeriodBase, RegistrationPeriodSettings, RegistrationPeriod as RegistrationPeriodStruct } from '@stamhoofd/structures';
4
4
  import { v4 as uuidv4 } from 'uuid';
5
5
 
6
- export class RegistrationPeriod extends Model {
6
+ export class RegistrationPeriod extends QueryableModel {
7
7
  static table = 'registration_periods';
8
8
 
9
9
  @column({
@@ -97,22 +97,4 @@ export class RegistrationPeriod extends Model {
97
97
 
98
98
  this.previousPeriodId = previousPeriod?.id ?? null;
99
99
  }
100
-
101
- /**
102
- * Experimental: needs to move to library
103
- */
104
- static select() {
105
- const transformer = (row: SQLResultNamespacedRow): RegistrationPeriod => {
106
- const d = (this as typeof RegistrationPeriod & typeof Model).fromRow(row[this.table] as any) as RegistrationPeriod | undefined;
107
-
108
- if (!d) {
109
- throw new Error('MemberPlatformMembership not found');
110
- }
111
-
112
- return d;
113
- };
114
-
115
- const select = new SQLSelect(transformer, SQL.wildcard());
116
- return select.from(SQL.table(this.table));
117
- }
118
100
  }
@@ -1,7 +1,8 @@
1
- import { column, Model } from '@simonbackx/simple-database';
1
+ import { column } from '@simonbackx/simple-database';
2
+ import { QueryableModel } from '@stamhoofd/sql';
2
3
  import { v4 as uuidv4 } from 'uuid';
3
4
 
4
- export class STCredit extends Model {
5
+ export class STCredit extends QueryableModel {
5
6
  static table = 'stamhoofd_credits';
6
7
 
7
8
  // Columns
@@ -1,10 +1,11 @@
1
- import { column, ManyToOneRelation, Model } from '@simonbackx/simple-database';
1
+ import { column, ManyToOneRelation } from '@simonbackx/simple-database';
2
+ import { QueryableModel } from '@stamhoofd/sql';
2
3
  import { STInvoiceMeta } from '@stamhoofd/structures';
3
4
  import { v4 as uuidv4 } from 'uuid';
4
5
 
5
6
  import { Organization, Payment } from './';
6
7
 
7
- export class STInvoice extends Model {
8
+ export class STInvoice extends QueryableModel {
8
9
  static table = 'stamhoofd_invoices';
9
10
 
10
11
  private static numberCache: number | null = null;
@@ -1,5 +1,6 @@
1
- import { column, Model } from '@simonbackx/simple-database';
1
+ import { column } from '@simonbackx/simple-database';
2
2
  import { SimpleError } from '@simonbackx/simple-errors';
3
+ import { QueryableModel } from '@stamhoofd/sql';
3
4
  import { EmailTemplateType, Recipient, Replacement, STPackageMeta, STPackageStatus, STPackageType } from '@stamhoofd/structures';
4
5
  import { Formatter } from '@stamhoofd/utility';
5
6
  import { v4 as uuidv4 } from 'uuid';
@@ -8,7 +9,7 @@ import { sendEmailTemplate } from '../helpers/EmailBuilder';
8
9
  import { GroupBuilder } from '../helpers/GroupBuilder';
9
10
  import { Organization } from './';
10
11
 
11
- export class STPackage extends Model {
12
+ export class STPackage extends QueryableModel {
12
13
  static table = 'stamhoofd_packages';
13
14
 
14
15
  // Columns
@@ -1,4 +1,5 @@
1
- import { column, ManyToOneRelation, Model } from '@simonbackx/simple-database';
1
+ import { column, ManyToOneRelation } from '@simonbackx/simple-database';
2
+ import { QueryableModel } from '@stamhoofd/sql';
2
3
  import { STInvoiceMeta } from '@stamhoofd/structures';
3
4
  import { v4 as uuidv4 } from 'uuid';
4
5
 
@@ -15,7 +16,7 @@ import { Organization } from './';
15
16
  *
16
17
  * So please make sure you don't edit existing items, unless you change the id
17
18
  */
18
- export class STPendingInvoice extends Model {
19
+ export class STPendingInvoice extends QueryableModel {
19
20
  static table = 'stamhoofd_pending_invoices';
20
21
 
21
22
  // Columns
@@ -1,12 +1,13 @@
1
1
  /* eslint-disable @typescript-eslint/no-unsafe-argument */
2
- import { column, Model } from '@simonbackx/simple-database';
2
+ import { column } from '@simonbackx/simple-database';
3
+ import { QueryableModel } from '@stamhoofd/sql';
3
4
  import { Requirements, StripeBusinessProfile, StripeCompany, StripeMetaAccountDashboardSettings, StripeMetaAccountSettings, StripeMetaData } from '@stamhoofd/structures';
4
5
  import { v4 as uuidv4 } from 'uuid';
5
6
 
6
7
  /**
7
8
  * Keeps track of how much a member/user owes or needs to be reimbursed.
8
9
  */
9
- export class StripeAccount extends Model {
10
+ export class StripeAccount extends QueryableModel {
10
11
  static table = 'stripe_accounts';
11
12
 
12
13
  @column({
@@ -1,7 +1,8 @@
1
- import { column, Model } from '@simonbackx/simple-database';
1
+ import { column } from '@simonbackx/simple-database';
2
+ import { QueryableModel } from '@stamhoofd/sql';
2
3
  import { v4 as uuidv4 } from 'uuid';
3
4
 
4
- export class StripeCheckoutSession extends Model {
5
+ export class StripeCheckoutSession extends QueryableModel {
5
6
  static table = 'stripe_checkout_sessions';
6
7
 
7
8
  @column({
@@ -1,7 +1,8 @@
1
- import { column, Model } from '@simonbackx/simple-database';
1
+ import { column } from '@simonbackx/simple-database';
2
+ import { QueryableModel } from '@stamhoofd/sql';
2
3
  import { v4 as uuidv4 } from 'uuid';
3
4
 
4
- export class StripePaymentIntent extends Model {
5
+ export class StripePaymentIntent extends QueryableModel {
5
6
  static table = 'stripe_payment_intents';
6
7
 
7
8
  @column({
@@ -1,4 +1,5 @@
1
- import { column, ManyToOneRelation, Model } from '@simonbackx/simple-database';
1
+ import { column, ManyToOneRelation } from '@simonbackx/simple-database';
2
+ import { QueryableModel } from '@stamhoofd/sql';
2
3
  import { CartReservedSeat } from '@stamhoofd/structures';
3
4
  import basex from 'base-x';
4
5
  import crypto from 'crypto';
@@ -27,7 +28,7 @@ async function randomBytes(size: number): Promise<Buffer> {
27
28
  * This avoids the select in the database, saving some bytes in network communication
28
29
  * (especially needed when clients requests all the changed tickets)
29
30
  */
30
- export class Ticket extends Model {
31
+ export class Ticket extends QueryableModel {
31
32
  static table = 'webshop_tickets';
32
33
 
33
34
  // Columns
@@ -1,4 +1,5 @@
1
- import { column, Database, ManyToOneRelation, Model } from '@simonbackx/simple-database';
1
+ import { column, Database, ManyToOneRelation } from '@simonbackx/simple-database';
2
+ import { QueryableModel } from '@stamhoofd/sql';
2
3
  import { ApiUser } from '@stamhoofd/structures';
3
4
  import crypto from 'crypto';
4
5
 
@@ -44,7 +45,7 @@ export const apiUserRateLimiter = new RateLimiter({
44
45
  ],
45
46
  });
46
47
 
47
- export class Token extends Model {
48
+ export class Token extends QueryableModel {
48
49
  static table = 'tokens';
49
50
  static MAX_DEVICES = 15;
50
51
 
@@ -1,7 +1,8 @@
1
- import { column, Model } from '@simonbackx/simple-database';
1
+ import { column } from '@simonbackx/simple-database';
2
+ import { QueryableModel } from '@stamhoofd/sql';
2
3
  import { v4 as uuidv4 } from 'uuid';
3
4
 
4
- export class UsedRegisterCode extends Model {
5
+ export class UsedRegisterCode extends QueryableModel {
5
6
  static table = 'used_register_codes';
6
7
 
7
8
  @column({
@@ -1,12 +1,14 @@
1
- import { column, Database, ManyToOneRelation, Model } from '@simonbackx/simple-database';
1
+ import { column, Database, ManyToOneRelation } from '@simonbackx/simple-database';
2
2
  import { EmailInterfaceRecipient } from '@stamhoofd/email';
3
+ import { QueryableModel } from '@stamhoofd/sql';
3
4
  import { LoginProviderType, NewUser, Permissions, Recipient, Replacement, UserMeta, UserPermissions, User as UserStruct } from '@stamhoofd/structures';
4
5
  import argon2 from 'argon2';
5
6
  import { v4 as uuidv4 } from 'uuid';
6
7
 
7
8
  import { Organization } from './';
9
+ import { QueueHandler } from '@stamhoofd/queues';
8
10
 
9
- export class User extends Model {
11
+ export class User extends QueryableModel {
10
12
  static table = 'users';
11
13
 
12
14
  // Columns
@@ -140,7 +142,7 @@ export class User extends Model {
140
142
  }
141
143
 
142
144
  return (
143
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
145
+
144
146
  await User.where(query)
145
147
  ).filter(a => !a.isApiUser);
146
148
  }
@@ -479,4 +481,30 @@ export class User extends Model {
479
481
  },
480
482
  ];
481
483
  }
484
+
485
+ /**
486
+ * Get internal system user that can be used on places that require a user object but the system is the actor
487
+ */
488
+ static async getSystem(): Promise<User> {
489
+ return QueueHandler.schedule('User.getSystem', async () => {
490
+ // Build a new one
491
+ let model = await this.getByID('1');
492
+ if (!model) {
493
+ // Create a new platform
494
+ model = new User();
495
+ model.id = '1';
496
+ model.firstName = 'System';
497
+ model.email = 'webmaster@stamhoofd.be';
498
+ model.verified = true;
499
+ model.permissions = UserPermissions.create({
500
+ globalPermissions: Permissions.full,
501
+ });
502
+ model.organizationId = null;
503
+
504
+ await model.save();
505
+ }
506
+
507
+ return model;
508
+ });
509
+ }
482
510
  }
@@ -1,10 +1,11 @@
1
- import { column, ManyToOneRelation, Model } from '@simonbackx/simple-database';
1
+ import { column, ManyToOneRelation } from '@simonbackx/simple-database';
2
+ import { QueryableModel } from '@stamhoofd/sql';
2
3
  import { Permissions } from '@stamhoofd/structures';
3
4
  import { v4 as uuidv4 } from 'uuid';
4
5
 
5
6
  import { Organization, User } from './';
6
7
 
7
- export class UserPermissions extends Model {
8
+ export class UserPermissions extends QueryableModel {
8
9
  static table = 'user_permissions';
9
10
 
10
11
  // Columns
@@ -1,12 +1,13 @@
1
- import { column, Database, ManyToOneRelation, Model } from '@simonbackx/simple-database';
1
+ import { column, Database, ManyToOneRelation } from '@simonbackx/simple-database';
2
2
  import { ArrayDecoder } from '@simonbackx/simple-encoding';
3
+ import { QueryableModel } from '@stamhoofd/sql';
3
4
  import { Category, DNSRecordStatus, Product, WebshopMetaData, WebshopPrivateMetaData, WebshopServerMetaData } from '@stamhoofd/structures';
4
5
  import { v4 as uuidv4 } from 'uuid';
5
6
  import { validateDNSRecords } from '../helpers/DNSValidator';
6
7
 
7
8
  import { Organization } from './';
8
9
 
9
- export class Webshop extends Model {
10
+ export class Webshop extends QueryableModel {
10
11
  static table = 'webshops';
11
12
 
12
13
  // Columns
@@ -1,9 +1,10 @@
1
- import { column, Model } from '@simonbackx/simple-database';
1
+ import { column } from '@simonbackx/simple-database';
2
2
  import { ArrayDecoder } from '@simonbackx/simple-encoding';
3
+ import { QueryableModel } from '@stamhoofd/sql';
3
4
  import { Discount, DiscountCode } from '@stamhoofd/structures';
4
5
  import { v4 as uuidv4 } from 'uuid';
5
6
 
6
- export class WebshopDiscountCode extends Model {
7
+ export class WebshopDiscountCode extends QueryableModel {
7
8
  static table = 'webshop_discount_codes';
8
9
 
9
10
  // Columns
@@ -1,10 +1,11 @@
1
- import { column, ManyToOneRelation, Model } from '@simonbackx/simple-database';
1
+ import { column, ManyToOneRelation } from '@simonbackx/simple-database';
2
2
  import { Country } from '@stamhoofd/structures';
3
3
  import { v4 as uuidv4 } from 'uuid';
4
4
 
5
+ import { QueryableModel } from '@stamhoofd/sql';
5
6
  import { Province } from './Province';
6
7
 
7
- export class City extends Model {
8
+ export class City extends QueryableModel {
8
9
  static table = 'cities';
9
10
 
10
11
  @column({
@@ -1,12 +1,13 @@
1
- import { column, Database, ManyToOneRelation, Model } from '@simonbackx/simple-database';
1
+ import { column, Database, ManyToOneRelation } from '@simonbackx/simple-database';
2
2
  import { SimpleError } from '@simonbackx/simple-errors';
3
+ import { QueryableModel } from '@stamhoofd/sql';
3
4
  import { Country } from '@stamhoofd/structures';
4
5
  import { Formatter, StringCompare } from '@stamhoofd/utility';
5
6
  import { v4 as uuidv4 } from 'uuid';
6
7
 
7
8
  import { City } from './City';
8
9
 
9
- export class PostalCode extends Model {
10
+ export class PostalCode extends QueryableModel {
10
11
  static table = 'postal_codes';
11
12
 
12
13
  @column({
@@ -1,8 +1,9 @@
1
- import { column, Model } from '@simonbackx/simple-database';
1
+ import { column } from '@simonbackx/simple-database';
2
+ import { QueryableModel } from '@stamhoofd/sql';
2
3
  import { Country } from '@stamhoofd/structures';
3
4
  import { v4 as uuidv4 } from 'uuid';
4
5
 
5
- export class Province extends Model {
6
+ export class Province extends QueryableModel {
6
7
  static table = 'provinces';
7
8
 
8
9
  @column({
@@ -1,9 +1,10 @@
1
- import { column, ManyToOneRelation, Model } from '@simonbackx/simple-database';
1
+ import { column, ManyToOneRelation } from '@simonbackx/simple-database';
2
+ import { QueryableModel } from '@stamhoofd/sql';
2
3
  import { v4 as uuidv4 } from 'uuid';
3
4
 
4
5
  import { City } from './City';
5
6
 
6
- export class Street extends Model {
7
+ export class Street extends QueryableModel {
7
8
  static table = 'streets';
8
9
 
9
10
  @column({
@@ -53,3 +53,4 @@ export * from './EmailRecipient';
53
53
  export * from './Event';
54
54
  export * from './CachedBalance';
55
55
  export * from './AuditLog';
56
+ export * from './MemberUser';