@stamhoofd/models 2.24.0 → 2.25.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.
@@ -130,27 +130,19 @@ export class Organization extends Model {
130
130
 
131
131
  // Methods
132
132
  static async getByEmail(email: string): Promise<Organization | undefined> {
133
- if (["hallo@stamhoofd.be", "hallo@stamhoofd.nl"].includes(email)) {
134
- return
135
- }
136
133
  if (email.startsWith('noreply-')) {
137
134
  // Trim
138
135
  email = email.substring("noreply-".length)
139
136
  }
140
137
 
141
- if (email.endsWith("@stamhoofd.email")) {
142
- const uri = email.substring(0, email.length - "@stamhoofd.email".length)
143
- return await Organization.getByURI(uri)
144
- }
145
-
146
- if (email.endsWith("@stamhoofd.be")) {
147
- const uri = email.substring(0, email.length - "@stamhoofd.be".length)
148
- return await Organization.getByURI(uri)
149
- }
150
-
151
- if (email.endsWith("@stamhoofd.nl")) {
152
- const uri = email.substring(0, email.length - "@stamhoofd.nl".length)
153
- return await Organization.getByURI(uri)
138
+ for (const domain of [
139
+ ...Object.values(STAMHOOFD.domains.defaultBroadcastEmail ?? {}),
140
+ ...Object.values(STAMHOOFD.domains.defaultTransactionalEmail ?? {}),
141
+ ]) {
142
+ if (email.endsWith("@" + domain)) {
143
+ const uri = email.substring(0, email.length - ("@" + domain).length)
144
+ return await Organization.getByURI(uri)
145
+ }
154
146
  }
155
147
 
156
148
  const at = email.indexOf("@");
@@ -872,38 +864,27 @@ export class Organization extends Model {
872
864
  }
873
865
 
874
866
  /**
875
- * These email addresess are private
867
+ * Return default e-mail address if no email addresses are set.
876
868
  */
877
- async getInvoicingToEmails() {
878
- // Circular reference fix
879
- const User = (await import('./User')).User;
880
- const admins = await User.where({ organizationId: this.id, permissions: { sign: "!=", value: null }})
881
- const filtered = admins.filter(a => a.permissions?.forOrganization(this)?.hasAccessRight(AccessRight.OrganizationFinanceDirector))
882
-
883
- if (filtered.length > 0) {
884
- return filtered.map(f => f.getEmailTo() ).join(", ")
885
- }
869
+ getDefaultFrom(i18n: I18n, withName = true, type: 'transactional' | 'broadcast' = 'broadcast') {
870
+ const domain = type === 'transactional' ? i18n.localizedDomains.defaultTransactionalEmail() : i18n.localizedDomains.defaultBroadcastEmail()
886
871
 
887
- return undefined
888
- }
889
-
890
- /**
891
- * Return default e-mail address for important e-mails that should have the highest deliverability
892
- */
893
- getStrongEmail(i18n: I18n, withName = true) {
894
872
  if (!withName) {
895
- return ('noreply-' + this.uri+"@"+i18n.$t("shared.domains.email"));
873
+ return ('noreply-' + this.uri+"@"+domain);
896
874
  }
897
- return '"'+this.name.replaceAll("\"", "\\\"")+'" <'+ ('noreply-' + this.uri+"@"+i18n.$t("shared.domains.email")) +'>'
875
+ return '"'+this.name.replaceAll("\"", "\\\"")+'" <'+ ('noreply-' + this.uri+"@"+domain) +'>'
898
876
  }
899
877
 
878
+ /**
879
+ * @deprecated Switch to EmailBuilder.sendEmailTemplate
880
+ */
900
881
  getEmail(id: string | null, strongDefault = false): { from: string; replyTo: string | undefined } {
901
882
  if (id === null) {
902
883
  return this.getDefaultEmail(strongDefault)
903
884
  }
904
885
 
905
886
  // Send confirmation e-mail
906
- let from = strongDefault ? this.getStrongEmail(this.i18n, false) : this.uri+"@stamhoofd.email";
887
+ let from = this.getDefaultFrom(this.i18n, false, strongDefault ? 'transactional' : 'broadcast')
907
888
  const sender: OrganizationEmail | undefined = this.privateMeta.emails.find(e => e.id === id)
908
889
  let replyTo: string | undefined = undefined
909
890
 
@@ -935,13 +916,12 @@ export class Organization extends Model {
935
916
  return this.getDefaultEmail(strongDefault)
936
917
  }
937
918
 
938
- getGroupEmail(group: Group) {
939
- return this.getEmail(group.privateSettings.defaultEmailId)
940
- }
941
-
919
+ /**
920
+ * @deprecated Switch to EmailBuilder.sendEmailTemplate
921
+ */
942
922
  getDefaultEmail(strongDefault = false): { from: string; replyTo: string | undefined } {
943
923
  // Send confirmation e-mail
944
- let from = strongDefault ? this.getStrongEmail(this.i18n, false) : this.uri+"@stamhoofd.email";
924
+ let from = strongDefault ? this.getDefaultFrom(this.i18n, false) : this.uri+"@stamhoofd.email";
945
925
  const sender: OrganizationEmail | undefined = this.privateMeta.emails.find(e => e.default) ?? this.privateMeta.emails[0];
946
926
  let replyTo: string | undefined = undefined
947
927