save or complete transaction check

This commit is contained in:
Fran Jurmanović
2021-12-12 10:23:47 +01:00
parent 06dd67e6c5
commit b199408137
6 changed files with 97 additions and 41 deletions

View File

@@ -32,6 +32,8 @@
{ {
"ignoreRestSiblings": true "ignoreRestSiblings": true
} }
] ],
"no-console": "warn",
"no-debugger": "warn"
} }
} }

View File

@@ -129,7 +129,7 @@ class AppMainElement extends HTMLElement {
checkSubscriptions = async () => { checkSubscriptions = async () => {
if (this.isAuth && !this.subscriptionChecked) { if (this.isAuth && !this.subscriptionChecked) {
const checked = await this.transactionsService.check(); const checked = await this.transactionsService.check({ sortBy: 'transactionDate asc' });
this.createModal('transaction-check', { this.createModal('transaction-check', {
data: checked, data: checked,
}); });

View File

@@ -1,6 +1,6 @@
import { TemplateResult, controller, target, html } from 'core/utils'; import { TemplateResult, controller, target, html } from 'core/utils';
import { TransactionsService } from 'services/'; import { TransactionsService, TransactionStatusService } from 'services/';
import { AppMainElement, AppPaginationElement } from 'components/'; import { AppPaginationElement } from 'components/';
import { BasePageElement } from 'common/'; import { BasePageElement } from 'common/';
import { TransactionCheckElementTemplate } from 'pages/transaction-check'; import { TransactionCheckElementTemplate } from 'pages/transaction-check';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
@@ -8,6 +8,8 @@ import dayjs from 'dayjs';
@controller('transaction-check') @controller('transaction-check')
class TransactionCheckElement extends BasePageElement { class TransactionCheckElement extends BasePageElement {
private transactionsService: TransactionsService; private transactionsService: TransactionsService;
private transactionStatusService: TransactionStatusService;
transactionStatuses: [];
@target pagination: AppPaginationElement; @target pagination: AppPaginationElement;
modalData: any = null; modalData: any = null;
constructor() { constructor() {
@@ -16,7 +18,9 @@ class TransactionCheckElement extends BasePageElement {
}); });
} }
elementConnected = (): void => { elementConnected = async (): Promise<void> => {
this.transactionStatusService = new TransactionStatusService(this.appMain?.appService);
await this.fetchTransactionStatus();
this.transactionsService = new TransactionsService(this.appMain?.appService); this.transactionsService = new TransactionsService(this.appMain?.appService);
this.update(); this.update();
this.pagination?.setCustomRenderItem?.(this.renderSubscription)!; this.pagination?.setCustomRenderItem?.(this.renderSubscription)!;
@@ -32,7 +36,23 @@ class TransactionCheckElement extends BasePageElement {
return data; return data;
}; };
renderSubscription = (item) => html`<tr class="col-transactions"> renderSubscription = (item) => {
const renderEditActions = () => html`<span
><button class="btn btn-rounded btn-red" @click="${() => this.transactionEdit(item)}}">Cancel</button></span
><span
><button class="btn btn-rounded btn-primary" @click="${() => this.transactionEditSave(item)}}">
Save
</button></span
>`;
const renderRegularActions = () => html`<span
><button class="btn btn-rounded btn-primary" @click="${() => this.transactionEdit(item)}}">Edit</button></span
>
<span
><button class="btn btn-rounded btn-green" @click="${() => this.transactionEditComplete(item)}}">
Complete
</button></span
>`;
return html`<tr class="col-transactions">
${!item.isEdit ${!item.isEdit
? html`<td class="--left">${dayjs(item.transactionDate).format("MMM DD 'YY")}</td>` ? html`<td class="--left">${dayjs(item.transactionDate).format("MMM DD 'YY")}</td>`
: html`<input-field : html`<input-field
@@ -55,16 +75,38 @@ class TransactionCheckElement extends BasePageElement {
</span> </span>
<span class="currency">(${item.currency ? item.currency : 'USD'})</span> <span class="currency">(${item.currency ? item.currency : 'USD'})</span>
</td> </td>
<td class="--right"> <td class="--right">${item.isEdit ? renderEditActions() : renderRegularActions()}</td>
<span><button class="btn btn-rounded btn-gray" @click="${() => this.transactionEdit(item)}}">Edit</button></span>
</td>
</tr>`; </tr>`;
};
fetchTransactionStatus = async () => {
this.transactionStatuses = await this.transactionStatusService.getAll();
};
transactionEdit = (item) => { transactionEdit = (item) => {
item.isEdit = !item.isEdit; item.isEdit = !item.isEdit;
this.pagination?.update(); this.pagination?.update();
}; };
transactionEditSave = async (item) => {
const resource = {
transactionDate: dayjs(item.newTransactionDate || item.transactionDate)
.utc(true)
.format(),
};
await this.updateTransaction(item.id, resource);
};
transactionEditComplete = async (item) => {
const completedStatusId = (this.transactionStatuses?.find((item: any) => item.status === 'completed') as any)?.id!;
if (completedStatusId) {
const resource = {
transactionStatusId: completedStatusId,
};
await this.updateTransaction(item.id, resource);
}
};
transactionUpdated = () => { transactionUpdated = () => {
this.pagination?.executeFetch(); this.pagination?.executeFetch();
}; };
@@ -72,11 +114,22 @@ class TransactionCheckElement extends BasePageElement {
getTransactions = async (options): Promise<any> => { getTransactions = async (options): Promise<any> => {
try { try {
options.embed = 'TransactionType'; options.embed = 'TransactionType';
options.sortBy = 'dateCreated|desc'; options.sortBy = 'transactionDate|asc';
const response = await this.transactionsService.check(options); const response = await this.transactionsService.check(options);
return this.mappedData(response);
} catch (err) {
throw err;
}
};
updateTransaction = async (id, resource): Promise<any> => {
try {
const response = await this.transactionsService.put(id, resource);
return response; return response;
} catch (err) { } catch (err) {
throw err; throw err;
} finally {
this.pagination?.defaultFetch();
} }
}; };

View File

@@ -1,16 +1,7 @@
import { html, nothing, TemplateResult } from 'core/utils'; import { html, nothing, TemplateResult } from 'core/utils';
export default (props): TemplateResult => { export default (props): TemplateResult => {
const { walletId } = props;
const renderWallet = () => {
if (walletId) {
return html`<span>${walletId}</span>`;
}
return nothing;
};
return html`<div> return html`<div>
${renderWallet()}
<app-pagination data-target="transaction-check.pagination"></app-pagination> <app-pagination data-target="transaction-check.pagination"></app-pagination>
</div>`; </div>`;
}; };

View File

@@ -0,0 +1,9 @@
import { AppService, BaseService } from 'core/services';
class TransactionStatusService extends BaseService {
constructor(appService: AppService) {
super('/transaction-status', appService);
}
}
export default TransactionStatusService;

View File

@@ -5,3 +5,4 @@ export { default as TransactionsService } from './TransactionsService';
export { default as TransactionTypeService } from './TransactionTypeService'; export { default as TransactionTypeService } from './TransactionTypeService';
export { default as SubscriptionService } from './SubscriptionService'; export { default as SubscriptionService } from './SubscriptionService';
export { default as SubscriptionTypeService } from './SubscriptionTypeService'; export { default as SubscriptionTypeService } from './SubscriptionTypeService';
export { default as TransactionStatusService } from './TransactionStatusService';