Skip to content

Commit

Permalink
Added db patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac-GC committed Feb 1, 2024
1 parent aebdeaa commit e8afb20
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
7 changes: 7 additions & 0 deletions backend/patches/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import fixRoundOffAccount from './fixRoundOffAccount';
import testPatch from './testPatch';
import updateSchemas from './updateSchemas';
import setPaymentReferenceType from './setPaymentReferenceType';
import fixLedgerDateTime from './v0_21_0/fixLedgerDateTime';

export default [
{ name: 'testPatch', version: '0.5.0-beta.0', patch: testPatch },
Expand Down Expand Up @@ -34,4 +35,10 @@ export default [
version: '0.20.1',
patch: setPaymentReferenceType,
},
{
name: 'fixLedgerDateTime',
version: '0.21.1',
patch: fixLedgerDateTime

Check warning on line 41 in backend/patches/index.ts

View workflow job for this annotation

GitHub Actions / setup_and_lint

Replace `⏎` with `,`

}

Check warning on line 43 in backend/patches/index.ts

View workflow job for this annotation

GitHub Actions / setup_and_lint

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

async function execute(dm: DatabaseManager) {

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

View workflow job for this annotation

GitHub Actions / setup_and_lint

Delete `⏎··`
await dm.db!.knex!('AccountingLedgerEntry')
.select('name','date', 'referenceName')

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

View workflow job for this annotation

GitHub Actions / setup_and_lint

Replace `········.select('name',` with `····.select('name',·`
.then((trx) => {

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

View workflow job for this annotation

GitHub Actions / setup_and_lint

Delete `····`
trx.forEach(async entry => {

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

View workflow job for this annotation

GitHub Actions / setup_and_lint

Replace `······trx.forEach(async·entry` with `trx.forEach(async·(entry)`

Check warning on line 8 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, entry.referenceName, dm);

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

View workflow job for this annotation

GitHub Actions / setup_and_lint

Replace `················await·updateDateTimeForEntryType('PurchaseInvoice',·entry.name,·entry.referenceName,·dm);` with `········await·updateDateTimeForEntryType(⏎··········'PurchaseInvoice',⏎··········entry.name,⏎··········entry.referenceName,⏎··········dm`

Check failure on line 9 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

Check failure on line 9 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 9 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
await updateDateTimeForEntryType('SalesInvoice', entry.name, entry.referenceName, dm);

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

View workflow job for this annotation

GitHub Actions / setup_and_lint

Replace `········await·updateDateTimeForEntryType('SalesInvoice',·entry.name,·entry.referenceName,·dm);` with `);⏎········await·updateDateTimeForEntryType(⏎··········'SalesInvoice',⏎··········entry.name,⏎··········entry.referenceName,⏎··········dm`

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

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 argument of type `any` assigned to a parameter of type `String`

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 .referenceName on an `any` value
await updateDateTimeForEntryType('JournalEntry', entry.name, entry.referenceName, dm);

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

View workflow job for this annotation

GitHub Actions / setup_and_lint

Replace `········await·updateDateTimeForEntryType('JournalEntry',·entry.name,·entry.referenceName,·dm);` with `);⏎········await·updateDateTimeForEntryType(⏎··········'JournalEntry',⏎··········entry.name,⏎··········entry.referenceName,⏎··········dm`

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 .name on an `any` value

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
await updateDateTimeForEntryType('Payment', entry.name, entry.referenceName, dm);

Check failure on line 12 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
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 });

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) });
}
}

export default { execute, beforeMigrate: true };
1 change: 1 addition & 0 deletions models/Transactional/LedgerPosting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export class LedgerPosting {
dtFixedValue.setHours(0 - dtHours);
dtFixedValue.setMinutes(0 - dtMinutes);
dtFixedValue.setSeconds(0);
dtFixedValue.setMilliseconds(0);

// end ugly timezone fix code

Expand Down

0 comments on commit e8afb20

Please sign in to comment.