mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
- feat: remove unnecessary migrations, controllers and models files.
- feat: metable store - feat: metable store with settings store. - feat: settings middleware to auto-save and load. - feat: DI db manager to master container. - feat: write some logs to sale invoices.
This commit is contained in:
@@ -25,15 +25,15 @@ export default class ComputeItemCostJob {
|
||||
const Logger = Container.get('logger');
|
||||
const { startingDate, itemId, costMethod = 'FIFO' } = job.attrs.data;
|
||||
|
||||
Logger.debug(`Compute item cost - started: ${job.attrs.data}`);
|
||||
Logger.info(`Compute item cost - started: ${job.attrs.data}`);
|
||||
|
||||
try {
|
||||
await InventoryService.computeItemCost(startingDate, itemId, costMethod);
|
||||
Logger.debug(`Compute item cost - completed: ${job.attrs.data}`);
|
||||
Logger.info(`Compute item cost - completed: ${job.attrs.data}`);
|
||||
done();
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
Logger.error(`Compute item cost: ${job.attrs.data}, error: ${e}`);
|
||||
Logger.info(`Compute item cost: ${job.attrs.data}, error: ${e}`);
|
||||
done(e);
|
||||
}
|
||||
}
|
||||
@@ -58,9 +58,8 @@ export default class ComputeItemCostJob {
|
||||
async onJobFinished() {
|
||||
const agenda = Container.get('agenda');
|
||||
const startingDate = this.startingDate;
|
||||
this.depends = Math.max(this.depends - 1, 0);
|
||||
|
||||
console.log(startingDate);
|
||||
this.depends = Math.max(this.depends - 1, 0);
|
||||
|
||||
if (this.depends === 0) {
|
||||
this.startingDate = null;
|
||||
|
||||
@@ -3,7 +3,7 @@ import SubscriptionService from '@/services/Subscription/Subscription';
|
||||
|
||||
export default class MailNotificationSubscribeEnd {
|
||||
/**
|
||||
*
|
||||
* Job handler.
|
||||
* @param {Job} job -
|
||||
*/
|
||||
handler(job) {
|
||||
@@ -12,15 +12,15 @@ export default class MailNotificationSubscribeEnd {
|
||||
const subscriptionService = Container.get(SubscriptionService);
|
||||
const Logger = Container.get('logger');
|
||||
|
||||
Logger.debug(`Send mail notification subscription end soon - started: ${job.attrs.data}`);
|
||||
Logger.info(`Send mail notification subscription end soon - started: ${job.attrs.data}`);
|
||||
|
||||
try {
|
||||
subscriptionService.mailMessages.sendRemainingTrialPeriod(
|
||||
phoneNumber, remainingDays,
|
||||
);
|
||||
Logger.debug(`Send mail notification subscription end soon - finished: ${job.attrs.data}`);
|
||||
Logger.info(`Send mail notification subscription end soon - finished: ${job.attrs.data}`);
|
||||
} catch(error) {
|
||||
Logger.error(`Send mail notification subscription end soon - failed: ${job.attrs.data}, error: ${e}`);
|
||||
Logger.info(`Send mail notification subscription end soon - failed: ${job.attrs.data}, error: ${e}`);
|
||||
done(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,15 +12,15 @@ export default class MailNotificationTrialEnd {
|
||||
const subscriptionService = Container.get(SubscriptionService);
|
||||
const Logger = Container.get('logger');
|
||||
|
||||
Logger.debug(`Send mail notification subscription end soon - started: ${job.attrs.data}`);
|
||||
Logger.info(`Send mail notification subscription end soon - started: ${job.attrs.data}`);
|
||||
|
||||
try {
|
||||
subscriptionService.mailMessages.sendRemainingTrialPeriod(
|
||||
phoneNumber, remainingDays,
|
||||
);
|
||||
Logger.debug(`Send mail notification subscription end soon - finished: ${job.attrs.data}`);
|
||||
Logger.info(`Send mail notification subscription end soon - finished: ${job.attrs.data}`);
|
||||
} catch(error) {
|
||||
Logger.error(`Send mail notification subscription end soon - failed: ${job.attrs.data}, error: ${e}`);
|
||||
Logger.info(`Send mail notification subscription end soon - failed: ${job.attrs.data}, error: ${e}`);
|
||||
done(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,44 +1,28 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import Mustache from 'mustache';
|
||||
import { Container } from 'typedi';
|
||||
import { Container, Inject } from 'typedi';
|
||||
import AuthenticationService from '@/services/Authentication';
|
||||
|
||||
export default class WelcomeEmailJob {
|
||||
@Inject()
|
||||
authService: AuthenticationService;
|
||||
|
||||
export default class ResetPasswordMailJob {
|
||||
/**
|
||||
*
|
||||
* @param job
|
||||
* @param done
|
||||
* Handle send welcome mail job.
|
||||
* @param {Job} job
|
||||
* @param {Function} done
|
||||
*/
|
||||
handler(job, done) {
|
||||
const { user, token } = job.attrs.data;
|
||||
|
||||
public async handler(job, done: Function): Promise<void> {
|
||||
const { email, organizationName, firstName } = job.attrs.data;
|
||||
const Logger = Container.get('logger');
|
||||
const Mail = Container.get('mail');
|
||||
|
||||
const filePath = path.join(global.rootPath, 'views/mail/ResetPassword.html');
|
||||
const template = fs.readFileSync(filePath, 'utf8');
|
||||
const rendered = Mustache.render(template, {
|
||||
url: `https://google.com/reset/${token}`,
|
||||
first_name: user.firstName,
|
||||
last_name: user.lastName,
|
||||
// contact_us_email: config.contactUsMail,
|
||||
});
|
||||
|
||||
const mailOptions = {
|
||||
to: user.email,
|
||||
from: `${process.env.MAIL_FROM_NAME} ${process.env.MAIL_FROM_ADDRESS}`,
|
||||
subject: 'Bigcapital - Password Reset',
|
||||
html: rendered,
|
||||
};
|
||||
Mail.sendMail(mailOptions, (error) => {
|
||||
if (error) {
|
||||
Logger.info('[send_reset_password] failed send reset password mail', { error, user });
|
||||
done(error);
|
||||
return;
|
||||
}
|
||||
Logger.info('[send_reset_password] user has been sent reset password email successfuly.', { user });
|
||||
done();
|
||||
});
|
||||
res.status(200).send({ email: passwordReset.email });
|
||||
Logger.info(`Send reset password mail - started: ${job.attrs.data}`);
|
||||
|
||||
try {
|
||||
await this.authService.mailMessages.sendResetPasswordMessage();
|
||||
Logger.info(`Send reset password mail - finished: ${job.attrs.data}`);
|
||||
done()
|
||||
} catch (error) {
|
||||
Logger.info(`Send reset password mail - error: ${job.attrs.data}, error: ${error}`);
|
||||
done(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,15 +13,15 @@ export default class SMSNotificationSubscribeEnd {
|
||||
const subscriptionService = Container.get(SubscriptionService);
|
||||
const Logger = Container.get('logger');
|
||||
|
||||
Logger.debug(`Send SMS notification subscription end soon - started: ${job.attrs.data}`);
|
||||
Logger.info(`Send SMS notification subscription end soon - started: ${job.attrs.data}`);
|
||||
|
||||
try {
|
||||
subscriptionService.smsMessages.sendRemainingSubscriptionPeriod(
|
||||
phoneNumber, remainingDays,
|
||||
);
|
||||
Logger.debug(`Send SMS notification subscription end soon - finished: ${job.attrs.data}`);
|
||||
Logger.info(`Send SMS notification subscription end soon - finished: ${job.attrs.data}`);
|
||||
} catch(error) {
|
||||
Logger.error(`Send SMS notification subscription end soon - failed: ${job.attrs.data}, error: ${e}`);
|
||||
Logger.info(`Send SMS notification subscription end soon - failed: ${job.attrs.data}, error: ${e}`);
|
||||
done(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,15 +13,15 @@ export default class SMSNotificationTrialEnd {
|
||||
const subscriptionService = Container.get(SubscriptionService);
|
||||
const Logger = Container.get('logger');
|
||||
|
||||
Logger.debug(`Send notification subscription end soon - started: ${job.attrs.data}`);
|
||||
Logger.info(`Send notification subscription end soon - started: ${job.attrs.data}`);
|
||||
|
||||
try {
|
||||
subscriptionService.smsMessages.sendRemainingTrialPeriod(
|
||||
phoneNumber, remainingDays,
|
||||
);
|
||||
Logger.debug(`Send notification subscription end soon - finished: ${job.attrs.data}`);
|
||||
Logger.info(`Send notification subscription end soon - finished: ${job.attrs.data}`);
|
||||
} catch(error) {
|
||||
Logger.error(`Send notification subscription end soon - failed: ${job.attrs.data}, error: ${e}`);
|
||||
Logger.info(`Send notification subscription end soon - failed: ${job.attrs.data}, error: ${e}`);
|
||||
done(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,10 @@ import VoucherService from '@/services/Payment/Voucher';
|
||||
|
||||
export default class SendVoucherViaPhoneJob {
|
||||
public async handler(job, done: Function): Promise<void> {
|
||||
const { phoneNumber, voucherCode } = job.attrs.data;
|
||||
|
||||
const Logger = Container.get('logger');
|
||||
const voucherService = Container.get(VoucherService);
|
||||
const { phoneNumber, voucherCode } = job.attrs.data;
|
||||
|
||||
Logger.debug(`Send voucher via phone number - started: ${job.attrs.data}`);
|
||||
|
||||
|
||||
@@ -1,8 +1,28 @@
|
||||
|
||||
import { Container, Inject } from 'typedi';
|
||||
import InviteUserService from '@/services/InviteUsers';
|
||||
|
||||
export default class UserInviteMailJob {
|
||||
@Inject()
|
||||
inviteUsersService: InviteUserService;
|
||||
|
||||
handler(job, done) {
|
||||
|
||||
/**
|
||||
* Handle invite user job.
|
||||
* @param {Job} job
|
||||
* @param {Function} done
|
||||
*/
|
||||
public async handler(job, done: Function): Promise<void> {
|
||||
const { email, organizationName, firstName } = job.attrs.data;
|
||||
const Logger = Container.get('logger');
|
||||
|
||||
Logger.info(`Send invite user mail - started: ${job.attrs.data}`);
|
||||
|
||||
try {
|
||||
await this.inviteUsersService.mailMessages.sendInviteMail();
|
||||
Logger.info(`Send invite user mail - finished: ${job.attrs.data}`);
|
||||
done()
|
||||
} catch (error) {
|
||||
Logger.info(`Send invite user mail - error: ${job.attrs.data}, error: ${error}`);
|
||||
done(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
28
server/src/jobs/WelcomeSMS.ts
Normal file
28
server/src/jobs/WelcomeSMS.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Container, Inject } from 'typedi';
|
||||
import AuthenticationService from '@/services/Authentication';
|
||||
|
||||
export default class WelcomeSMSJob {
|
||||
@Inject()
|
||||
authService: AuthenticationService;
|
||||
|
||||
/**
|
||||
* Handle send welcome mail job.
|
||||
* @param {Job} job
|
||||
* @param {Function} done
|
||||
*/
|
||||
public async handler(job, done: Function): Promise<void> {
|
||||
const { email, organizationName, firstName } = job.attrs.data;
|
||||
const Logger = Container.get('logger');
|
||||
|
||||
Logger.info(`Send welcome SMS message - started: ${job.attrs.data}`);
|
||||
|
||||
try {
|
||||
await this.authService.smsMessages.sendWelcomeMessage();
|
||||
Logger.info(`Send welcome SMS message - finished: ${job.attrs.data}`);
|
||||
done()
|
||||
} catch (error) {
|
||||
Logger.info(`Send welcome SMS message - error: ${job.attrs.data}, error: ${error}`);
|
||||
done(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,38 +1,28 @@
|
||||
import fs from 'fs';
|
||||
import Mustache from 'mustache';
|
||||
import path from 'path';
|
||||
import { Container } from 'typedi';
|
||||
import { Container, Inject } from 'typedi';
|
||||
import AuthenticationService from '@/services/Authentication';
|
||||
|
||||
export default class WelcomeEmailJob {
|
||||
@Inject()
|
||||
authService: AuthenticationService;
|
||||
|
||||
/**
|
||||
*
|
||||
* Handle send welcome mail job.
|
||||
* @param {Job} job
|
||||
* @param {Function} done
|
||||
*/
|
||||
public async handler(job, done: Function): Promise<void> {
|
||||
const { email, organizationName, firstName } = job.attrs.data;
|
||||
const Logger = Container.get('logger');
|
||||
const Mail = Container.get('mail');
|
||||
|
||||
const filePath = path.join(global.rootPath, 'views/mail/Welcome.html');
|
||||
const template = fs.readFileSync(filePath, 'utf8');
|
||||
const rendered = Mustache.render(template, {
|
||||
email, organizationName, firstName,
|
||||
});
|
||||
const mailOptions = {
|
||||
to: email,
|
||||
from: `${process.env.MAIL_FROM_NAME} ${process.env.MAIL_FROM_ADDRESS}`,
|
||||
subject: 'Welcome to Bigcapital',
|
||||
html: rendered,
|
||||
};
|
||||
Mail.sendMail(mailOptions, (error) => {
|
||||
if (error) {
|
||||
Logger.error('Failed send welcome mail', { error, form });
|
||||
done(error);
|
||||
return;
|
||||
}
|
||||
Logger.info('User has been sent welcome email successfuly.', { form });
|
||||
done();
|
||||
});
|
||||
Logger.info(`Send welcome mail message - started: ${job.attrs.data}`);
|
||||
|
||||
try {
|
||||
await this.authService.mailMessages.sendWelcomeMessage();
|
||||
Logger.info(`Send welcome mail message - finished: ${job.attrs.data}`);
|
||||
done()
|
||||
} catch (error) {
|
||||
Logger.info(`Send welcome mail message - error: ${job.attrs.data}, error: ${error}`);
|
||||
done(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,15 +7,15 @@ export default class WriteInvoicesJournalEntries {
|
||||
const Logger = Container.get('logger');
|
||||
const { startingDate } = job.attrs.data;
|
||||
|
||||
Logger.debug(`Write sales invoices journal entries - started: ${job.attrs.data}`);
|
||||
Logger.info(`Write sales invoices journal entries - started: ${job.attrs.data}`);
|
||||
|
||||
try {
|
||||
await SalesInvoicesCost.writeJournalEntries(startingDate, true);
|
||||
Logger.debug(`Write sales invoices journal entries - completed: ${job.attrs.data}`);
|
||||
Logger.info(`Write sales invoices journal entries - completed: ${job.attrs.data}`);
|
||||
done();
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
Logger.error(`Write sales invoices journal entries: ${job.attrs.data}, error: ${e}`);
|
||||
Logger.info(`Write sales invoices journal entries: ${job.attrs.data}, error: ${e}`);
|
||||
done(e);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user