pangea-server 3.3.24 → 3.3.26

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.
@@ -91,8 +91,8 @@ class Db {
91
91
  const ids = [...new Set(result.map((item) => item[keyId]).filter(Boolean))];
92
92
  if (!ids.length)
93
93
  continue;
94
- const model = relations[key];
95
- const instances = await this.findMany(model, { where: { id: { [_1.Ops.in]: ids } } });
94
+ const relModel = relations[key];
95
+ const instances = await this.findMany(relModel, { where: { id: { [_1.Ops.in]: ids } } });
96
96
  result.forEach((item) => (item[key] = instances.find((instance) => instance.id === item[keyId]) || null));
97
97
  }
98
98
  return result;
@@ -122,10 +122,16 @@ class Arca {
122
122
  };
123
123
  try {
124
124
  const res = await this.__afip.ElectronicBilling.createVoucher(params);
125
- return { voucherNumber, cae: res.CAE, caeExpirationDate: res.CAEFchVto };
125
+ const finalRes = { voucherNumber, cae: res.CAE, caeExpirationDate: res.CAEFchVto };
126
+ (0, helpers_1.printSuccess)('arca', 'Voucher created successfully');
127
+ console.log(`params: ${params}`);
128
+ console.log(`res: ${finalRes}`);
129
+ return finalRes;
126
130
  }
127
131
  catch (err) {
128
- (0, helpers_1.printDanger)('arca', err);
132
+ (0, helpers_1.printDanger)('arca', 'Error creating voucher');
133
+ console.log(`params: ${params}`);
134
+ console.log(err);
129
135
  helpers_1.AppError.Throw({ statusCodeName: 'INTERNAL_SERVER_ERROR', errorCode: 'VOUCHER_CREATION_FAILED' });
130
136
  }
131
137
  }
@@ -6,8 +6,10 @@ type MailerConfig = {
6
6
  user: string;
7
7
  pass: string;
8
8
  };
9
+ name: string;
9
10
  };
10
11
  type SendMailOptions = {
12
+ name?: string;
11
13
  from?: string;
12
14
  to: string | string[];
13
15
  subject: string;
@@ -27,6 +29,7 @@ type SendMailConfig = {
27
29
  export declare class Mailer {
28
30
  private __transporter;
29
31
  private __user;
32
+ private __from;
30
33
  constructor(config: MailerConfig);
31
34
  sendMail(options: SendMailOptions, config?: SendMailConfig): Promise<any>;
32
35
  }
@@ -5,24 +5,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Mailer = void 0;
7
7
  const nodemailer_1 = __importDefault(require("nodemailer"));
8
+ // helpers
9
+ const helpers_1 = require("../helpers");
8
10
  class Mailer {
9
11
  constructor(config) {
10
- this.__transporter = nodemailer_1.default.createTransport({
11
- host: `smtp.${config.smtpProvider}.com`,
12
- port: config.port,
13
- secure: config.port === 465,
14
- auth: config.auth,
15
- });
16
- this.__user = config.auth.user;
12
+ const { smtpProvider, port, auth, name } = config;
13
+ const host = `smtp.${smtpProvider}.com`;
14
+ this.__transporter = nodemailer_1.default.createTransport({ host, port, secure: port === 465, auth });
15
+ this.__user = auth.user;
16
+ this.__from = `${name} <${auth.user}>`;
17
17
  }
18
18
  async sendMail(options, config) {
19
+ const { name, from, ...restOptions } = options;
20
+ const finalOptions = { ...restOptions, from: from || (name ? `${name} <${this.__user}>` : this.__from) };
19
21
  try {
20
- const mailOptions = { ...options, from: options.from || this.__user };
21
- const res = await this.__transporter.sendMail(mailOptions);
22
+ const res = await this.__transporter.sendMail(finalOptions);
23
+ (0, helpers_1.printSuccess)('mailer', 'Mail sent successfully');
24
+ console.log(`options: ${finalOptions}`);
25
+ console.log(`res: ${res}`);
22
26
  return res;
23
27
  }
24
28
  catch (err) {
25
- console.log('Error sending mail');
29
+ (0, helpers_1.printDanger)('mailer', 'Error sending mail');
30
+ console.log(`options: ${finalOptions}`);
31
+ console.log(err);
26
32
  if (config?.throwError)
27
33
  throw err;
28
34
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pangea-server",
3
3
  "description": "",
4
- "version": "3.3.24",
4
+ "version": "3.3.26",
5
5
  "files": [
6
6
  "dist"
7
7
  ],