-
-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AccountingCategory: add support for orders (#9695)
* feat(AccountingCategory): add support for orders * Add created at to accounting category (#9702) * Add created at to accounting category schema * Handle enum array type with sequelize * Use abstrat type to workaround sequelize pq enum naming * Make unique expense types in setter * prettier --------- Co-authored-by: Henrique <[email protected]>
- Loading branch information
Showing
23 changed files
with
534 additions
and
92 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
migrations/20240116123253-link-accounting-categories-to-contributions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
/** @type {import('sequelize-cli').Migration} */ | ||
module.exports = { | ||
async up(queryInterface, Sequelize) { | ||
// Reference accounting category from the `Orders` table | ||
await queryInterface.addColumn('OrderHistories', 'AccountingCategoryId', { | ||
type: Sequelize.INTEGER, | ||
allowNull: true, | ||
}); | ||
|
||
await queryInterface.addColumn('Orders', 'AccountingCategoryId', { | ||
type: Sequelize.INTEGER, | ||
references: { key: 'id', model: 'AccountingCategories' }, | ||
onDelete: 'SET NULL', | ||
onUpdate: 'CASCADE', | ||
allowNull: true, | ||
}); | ||
|
||
// Add a kind column to accounting categories | ||
await queryInterface.addColumn('AccountingCategories', 'kind', { | ||
type: Sequelize.ENUM('ADDED_FUNDS', 'CONTRIBUTION', 'EXPENSE'), | ||
allowNull: true, | ||
}); | ||
|
||
// Set default kind to expense, since we only had that until now | ||
await queryInterface.sequelize.query(` | ||
UPDATE "AccountingCategories" | ||
SET "kind" = 'EXPENSE' | ||
WHERE "kind" IS NULL | ||
`); | ||
}, | ||
|
||
async down(queryInterface) { | ||
await queryInterface.removeColumn('OrderHistories', 'AccountingCategoryId'); | ||
await queryInterface.removeColumn('Orders', 'AccountingCategoryId'); | ||
await queryInterface.removeColumn('AccountingCategories', 'kind'); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { GraphQLEnumType } from 'graphql'; | ||
|
||
import { AccountingCategoryKindList } from '../../../models/AccountingCategory'; | ||
|
||
export const GraphQLAccountingCategoryKind = new GraphQLEnumType({ | ||
name: 'AccountingCategoryKind', | ||
values: AccountingCategoryKindList.reduce((values, key) => { | ||
return { ...values, [key]: { value: key } }; | ||
}, {}), | ||
}); |
Oops, something went wrong.