Skip to content

Commit

Permalink
Formatting dbpatch
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac-GC committed Feb 1, 2024
1 parent e8afb20 commit 904fca8
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 28 deletions.
5 changes: 2 additions & 3 deletions backend/patches/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export default [
{
name: 'fixLedgerDateTime',
version: '0.21.1',
patch: fixLedgerDateTime

}
patch: fixLedgerDateTime,
},
] as Patch[];
84 changes: 59 additions & 25 deletions backend/patches/v0_21_0/fixLedgerDateTime.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,67 @@
import { DatabaseManager } from '../../database/manager';

async function execute(dm: DatabaseManager) {

await dm.db!.knex!('AccountingLedgerEntry')
.select('name','date', 'referenceName')
.then((trx) => {
trx.forEach(async entry => {
await updateDateTimeForEntryType('PurchaseInvoice', entry.name, entry.referenceName, dm);
await updateDateTimeForEntryType('SalesInvoice', entry.name, entry.referenceName, dm);
await updateDateTimeForEntryType('JournalEntry', entry.name, entry.referenceName, dm);
await updateDateTimeForEntryType('Payment', entry.name, entry.referenceName, dm);
await updateDateTimeForEntryType('StockMovement', entry.name, entry.referenceName, dm);
await updateDateTimeForEntryType('StockTransfer', entry.name, entry.referenceName, dm);
})
});
await dm.db!.knex!('AccountingLedgerEntry')
.select('name', 'date', 'referenceName')
.then((trx) => {
trx.forEach(async (entry) => {

Check warning on line 7 in backend/patches/v0_21_0/fixLedgerDateTime.ts

View workflow job for this annotation

GitHub Actions / setup_and_lint

Promise returned in function argument where a void return was expected
await updateDateTimeForEntryType(
'PurchaseInvoice',
entry.name,

Check failure on line 10 in backend/patches/v0_21_0/fixLedgerDateTime.ts

View workflow job for this annotation

GitHub Actions / setup_and_lint

Unsafe member access .name on an `any` value
entry.referenceName,

Check failure on line 11 in backend/patches/v0_21_0/fixLedgerDateTime.ts

View workflow job for this annotation

GitHub Actions / setup_and_lint

Unsafe argument of type `any` assigned to a parameter of type `String`

Check failure on line 11 in backend/patches/v0_21_0/fixLedgerDateTime.ts

View workflow job for this annotation

GitHub Actions / setup_and_lint

Unsafe member access .referenceName on an `any` value
dm
);
await updateDateTimeForEntryType(
'SalesInvoice',
entry.name,

Check failure on line 16 in backend/patches/v0_21_0/fixLedgerDateTime.ts

View workflow job for this annotation

GitHub Actions / setup_and_lint

Unsafe member access .name on an `any` value
entry.referenceName,

Check failure on line 17 in backend/patches/v0_21_0/fixLedgerDateTime.ts

View workflow job for this annotation

GitHub Actions / setup_and_lint

Unsafe argument of type `any` assigned to a parameter of type `String`

Check failure on line 17 in backend/patches/v0_21_0/fixLedgerDateTime.ts

View workflow job for this annotation

GitHub Actions / setup_and_lint

Unsafe member access .referenceName on an `any` value
dm
);
await updateDateTimeForEntryType(
'JournalEntry',
entry.name,

Check failure on line 22 in backend/patches/v0_21_0/fixLedgerDateTime.ts

View workflow job for this annotation

GitHub Actions / setup_and_lint

Unsafe member access .name on an `any` value
entry.referenceName,

Check failure on line 23 in backend/patches/v0_21_0/fixLedgerDateTime.ts

View workflow job for this annotation

GitHub Actions / setup_and_lint

Unsafe argument of type `any` assigned to a parameter of type `String`

Check failure on line 23 in backend/patches/v0_21_0/fixLedgerDateTime.ts

View workflow job for this annotation

GitHub Actions / setup_and_lint

Unsafe member access .referenceName on an `any` value
dm
);
await updateDateTimeForEntryType(
'Payment',
entry.name,

Check failure on line 28 in backend/patches/v0_21_0/fixLedgerDateTime.ts

View workflow job for this annotation

GitHub Actions / setup_and_lint

Unsafe member access .name on an `any` value
entry.referenceName,
dm
);
await updateDateTimeForEntryType(
'StockMovement',
entry.name,
entry.referenceName,
dm
);
await updateDateTimeForEntryType(
'StockTransfer',
entry.name,
entry.referenceName,
dm
);
});
});
}

async function updateDateTimeForEntryType(entryTypeTable: any, entryName: any, referenceName: String, dm: DatabaseManager) {
const refDate: Array<any> = await dm.db!.knex!(entryTypeTable)
.select('name','date')
.where({ 'name': referenceName });
async function updateDateTimeForEntryType(
entryTypeTable: any,

Check warning on line 49 in backend/patches/v0_21_0/fixLedgerDateTime.ts

View workflow job for this annotation

GitHub Actions / setup_and_lint

Unexpected any. Specify a different type
entryName: any,

Check warning on line 50 in backend/patches/v0_21_0/fixLedgerDateTime.ts

View workflow job for this annotation

GitHub Actions / setup_and_lint

Unexpected any. Specify a different type
referenceName: String,
dm: DatabaseManager
) {
const refDate: Array<any> = await dm.db!.knex!(entryTypeTable)

Check warning on line 54 in backend/patches/v0_21_0/fixLedgerDateTime.ts

View workflow job for this annotation

GitHub Actions / setup_and_lint

Unexpected any. Specify a different type
.select('name', 'date')
.where({ name: referenceName });

if (refDate.length > 0) {
const newDate = new Date(refDate[0].date)
console.log(entryName, refDate, new Date(refDate[0].date));
dm.db!.knex!('AccountingLedgerEntry')
.where({ name: entryName })
.update({ date: new Date(refDate[0].date) });
}
if (refDate.length > 0) {
const newDate = new Date(refDate[0].date);

Check warning on line 59 in backend/patches/v0_21_0/fixLedgerDateTime.ts

View workflow job for this annotation

GitHub Actions / setup_and_lint

'newDate' is assigned a value but never used
console.log(entryName, refDate, new Date(refDate[0].date));

Check warning on line 60 in backend/patches/v0_21_0/fixLedgerDateTime.ts

View workflow job for this annotation

GitHub Actions / setup_and_lint

Unexpected console statement
dm.db!.knex!('AccountingLedgerEntry')

Check warning on line 61 in backend/patches/v0_21_0/fixLedgerDateTime.ts

View workflow job for this annotation

GitHub Actions / setup_and_lint

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
.where({ name: entryName })
.update({ date: new Date(refDate[0].date) });
}
}

export default { execute, beforeMigrate: true };
export default { execute, beforeMigrate: true };

0 comments on commit 904fca8

Please sign in to comment.