fix: expense publish db column.

This commit is contained in:
Ahmed Bouhuolia
2020-09-29 16:32:01 +02:00
parent 9fbad4ac46
commit 35fce02c7a
4 changed files with 13 additions and 6 deletions

View File

@@ -8,7 +8,7 @@ exports.up = function(knex) {
table.integer('payment_account_id').unsigned();
table.integer('payee_id').unsigned();
table.string('reference_no');
table.boolean('published').defaultTo(false);
table.date('published_at');
table.integer('user_id').unsigned();
table.date('payment_date');
table.timestamps();

View File

@@ -8,7 +8,7 @@ export interface IExpense {
paymentAccountId: number,
peyeeId?: number,
referenceNo?: string,
published: boolean,
publishedAt: Date|null,
userId: number,
paymentDate: Date,
@@ -29,7 +29,7 @@ export interface IExpenseDTO {
paymentAccountId: number,
peyeeId?: number,
referenceNo?: string,
published: boolean,
publish: boolean,
userId: number,
paymentDate: Date,

View File

@@ -1,5 +1,6 @@
import TenantRepository from "./TenantRepository";
import { IExpense } from 'interfaces';
import moment from "moment";
export default class ExpenseRepository extends TenantRepository {
models: any;
@@ -31,7 +32,11 @@ export default class ExpenseRepository extends TenantRepository {
}
publish(expenseId: number) {
const { Expense } = this.models;
return Expense.query().findById(expenseId).patch({
publishedAt: moment().toMySqlDateTime(),
});
}
delete(expenseId: number) {

View File

@@ -1,5 +1,5 @@
import { Service, Inject } from "typedi";
import { difference, sumBy } from 'lodash';
import { difference, sumBy, omit } from 'lodash';
import moment from "moment";
import { ServiceError } from "exceptions";
import TenancyService from 'services/Tenancy/TenancyService';
@@ -244,14 +244,16 @@ export default class ExpensesService implements IExpensesService {
const totalAmount = sumBy(expenseDTO.categories, 'amount');
return {
published: false,
categories: [],
...expenseDTO,
...omit(expenseDTO, ['publish']),
totalAmount,
paymentDate: moment(expenseDTO.paymentDate).toMySqlDateTime(),
...(user) ? {
userId: user.id,
} : {},
...(expenseDTO.publish) ? {
publishedAt: moment().toMySqlDateTime(),
} : {},
}
}