-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit '8a2838e6c954d17e4b01fdaff44b5b33ad458dfe' into e2e_test…
…_mika
- Loading branch information
Showing
90 changed files
with
2,488 additions
and
656 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
packages/api/db/migration/20230817213340_rename_expense_type_other_to_miscellaneous.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,36 @@ | ||
/* | ||
* Copyright 2023 LiteFarm.org | ||
* This file is part of LiteFarm. | ||
* | ||
* LiteFarm is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* LiteFarm is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
export const up = async function (knex) { | ||
await knex('farmExpenseType').where({ expense_name: 'Other', farm_id: null }).update({ | ||
expense_name: 'Miscellaneous', | ||
expense_translation_key: 'MISCELLANEOUS', | ||
}); | ||
}; | ||
|
||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
export const down = async function (knex) { | ||
await knex('farmExpenseType').where({ expense_name: 'Miscellaneous', farm_id: null }).update({ | ||
expense_name: 'Other', | ||
expense_translation_key: 'OTHER', | ||
}); | ||
}; |
85 changes: 85 additions & 0 deletions
85
packages/api/db/migration/20230831015743_create_revenue_type_table.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,85 @@ | ||
/* | ||
* Copyright (c) 2023 LiteFarm.org | ||
* This file is part of LiteFarm. | ||
* | ||
* LiteFarm is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* LiteFarm is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
export const up = async function (knex) { | ||
await knex.schema.createTable('revenue_type', (table) => { | ||
table.increments('revenue_type_id').primary(); | ||
table.string('revenue_name').notNullable(); | ||
table.uuid('farm_id').references('farm_id').inTable('farm').defaultTo(null); | ||
table.boolean('deleted').notNullable().defaultTo(false); | ||
table.string('created_by_user_id').references('user_id').inTable('users'); | ||
table.string('updated_by_user_id').references('user_id').inTable('users'); | ||
table.dateTime('created_at').notNullable(); | ||
table.dateTime('updated_at').notNullable(); | ||
table.string('revenue_translation_key').notNullable(); | ||
}); | ||
|
||
await knex.schema.alterTable('sale', (table) => { | ||
table.integer('revenue_type_id').references('revenue_type_id').inTable('revenue_type'); | ||
}); | ||
|
||
// Prepopulate with one revenue type (crop_sale) | ||
await knex('revenue_type').insert({ | ||
revenue_type_id: 1, | ||
revenue_name: 'Crop Sale', | ||
farm_id: null, | ||
deleted: false, | ||
created_by_user_id: '1', | ||
updated_by_user_id: '1', | ||
created_at: new Date('2000/1/1').toISOString(), | ||
updated_at: new Date('2000/1/1').toISOString(), | ||
revenue_translation_key: 'CROP_SALE', | ||
}); | ||
|
||
// Reference crop_sale type for all existing records | ||
await knex('sale').update({ revenue_type_id: 1 }); | ||
|
||
// Add permissions | ||
await knex('permissions').insert([ | ||
{ permission_id: 138, name: 'add:revenue_types', description: 'add revenue types' }, | ||
{ permission_id: 139, name: 'delete:revenue_types', description: 'delete revenue types' }, | ||
{ permission_id: 140, name: 'edit:revenue_types', description: 'edit revenue types' }, | ||
{ permission_id: 141, name: 'get:revenue_types', description: 'get revenue types' }, | ||
]); | ||
|
||
await knex('rolePermissions').insert([ | ||
{ role_id: 1, permission_id: 138 }, | ||
{ role_id: 2, permission_id: 138 }, | ||
{ role_id: 5, permission_id: 138 }, | ||
{ role_id: 1, permission_id: 139 }, | ||
{ role_id: 2, permission_id: 139 }, | ||
{ role_id: 5, permission_id: 139 }, | ||
{ role_id: 1, permission_id: 140 }, | ||
{ role_id: 2, permission_id: 140 }, | ||
{ role_id: 5, permission_id: 140 }, | ||
{ role_id: 1, permission_id: 141 }, | ||
{ role_id: 2, permission_id: 141 }, | ||
{ role_id: 3, permission_id: 141 }, | ||
{ role_id: 5, permission_id: 141 }, | ||
]); | ||
}; | ||
|
||
export const down = async function (knex) { | ||
const permissions = [138, 139, 140, 141]; | ||
|
||
await knex('rolePermissions').whereIn('permission_id', permissions).del(); | ||
await knex('permissions').whereIn('permission_id', permissions).del(); | ||
|
||
await knex.schema.alterTable('sale', (table) => { | ||
table.dropColumn('revenue_type_id'); | ||
}); | ||
|
||
await knex.schema.dropTable('revenue_type'); | ||
}; |
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,52 @@ | ||
/* | ||
* Copyright 2023 LiteFarm.org | ||
* This file is part of LiteFarm. | ||
* | ||
* LiteFarm is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* LiteFarm is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import baseModel from './baseModel.js'; | ||
|
||
class RevenueType extends baseModel { | ||
static get tableName() { | ||
return 'revenue_type'; | ||
} | ||
|
||
static get idColumn() { | ||
return 'revenue_type_id'; | ||
} | ||
|
||
// Overriding the baseModel hidden to return the 'deleted' field | ||
static get hidden() { | ||
return ['created_at', 'created_by_user_id', 'updated_by_user_id', 'updated_at']; | ||
} | ||
|
||
// Optional JSON schema. This is not the database schema! Nothing is generated | ||
// based on this. This is only used for validation. Whenever a model instance | ||
// is created it is checked against this schema. http://json-schema.org/. | ||
static get jsonSchema() { | ||
return { | ||
type: 'object', | ||
required: ['revenue_name', 'farm_id'], | ||
|
||
properties: { | ||
revenue_type_id: { type: 'integer' }, | ||
revenue_name: { type: 'string', minLength: 1, maxLength: 100 }, | ||
farm_id: { type: 'string' }, | ||
revenue_translation_key: { type: 'string' }, | ||
...this.baseProperties, | ||
}, | ||
additionalProperties: false, | ||
}; | ||
} | ||
} | ||
|
||
export default RevenueType; |
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 |
---|---|---|
|
@@ -7,5 +7,5 @@ | |
"FUEL": "Fuel", | ||
"LAND": "Land", | ||
"SEEDS": "Seeds", | ||
"OTHER": "Other" | ||
"MISCELLANEOUS": "Miscellaneous" | ||
} |
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,3 @@ | ||
{ | ||
"CROP_SALE": "Crop Sale" | ||
} |
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
Oops, something went wrong.