forked from ytgov/elcc-data-management
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from icefoganalytics/main
Update from IceFog
- Loading branch information
Showing
29 changed files
with
1,229 additions
and
445 deletions.
There are no files selected for viewing
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,41 @@ | ||
import { isNil } from "lodash" | ||
|
||
import BaseController from "./base-controller" | ||
|
||
import { Centre } from "@/models" | ||
import { CentreServices } from "@/services" | ||
|
||
export class CentresController extends BaseController { | ||
async create() { | ||
try { | ||
const centre = await CentreServices.create(this.request.body, { | ||
currentUser: this.currentUser, | ||
}) | ||
return this.response.status(201).json({ centre }) | ||
} catch (error) { | ||
return this.response.status(422).json({ message: `Centre creation failed: ${error}` }) | ||
} | ||
} | ||
|
||
async update() { | ||
const centre = await this.loadCentre() | ||
if (isNil(centre)) { | ||
return this.response.status(404).json({ message: "Centre not found." }) | ||
} | ||
|
||
try { | ||
const updatedCentre = await CentreServices.update(centre, this.request.body, { | ||
currentUser: this.currentUser, | ||
}) | ||
return this.response.json({ centre: updatedCentre }) | ||
} catch (error) { | ||
return this.response.status(422).json({ message: `Centre update failed: ${error}` }) | ||
} | ||
} | ||
|
||
private loadCentre(): Promise<Centre | null> { | ||
return Centre.findByPk(this.params.centreId) | ||
} | ||
} | ||
|
||
export default CentresController |
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
81 changes: 81 additions & 0 deletions
81
api/src/db/migrations/2024.03.08T22.10.31.add-various-fields-to-centres-table.ts
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,81 @@ | ||
import { DataTypes } from "sequelize" | ||
|
||
import type { Migration } from "@/db/umzug" | ||
|
||
export const up: Migration = async ({ context: queryInterface }) => { | ||
await queryInterface.addColumn("centres", "license_holder_name", { | ||
type: DataTypes.STRING(100), | ||
allowNull: true, | ||
}) | ||
await queryInterface.addColumn("centres", "contact_name", { | ||
type: DataTypes.STRING(100), | ||
allowNull: true, | ||
}) | ||
await queryInterface.addColumn("centres", "physical_address", { | ||
type: DataTypes.STRING(250), | ||
allowNull: true, | ||
}) | ||
await queryInterface.addColumn("centres", "mailing_address", { | ||
type: DataTypes.STRING(250), | ||
allowNull: true, | ||
}) | ||
await queryInterface.addColumn("centres", "email", { | ||
type: DataTypes.STRING(100), | ||
allowNull: true, | ||
}) | ||
await queryInterface.addColumn("centres", "alt_email", { | ||
type: DataTypes.STRING(100), | ||
allowNull: true, | ||
}) | ||
await queryInterface.addColumn("centres", "phone_number", { | ||
type: DataTypes.STRING(20), | ||
allowNull: true, | ||
}) | ||
await queryInterface.addColumn("centres", "alt_phone_number", { | ||
type: DataTypes.STRING(20), | ||
allowNull: true, | ||
}) | ||
await queryInterface.addColumn("centres", "fax_number", { | ||
type: DataTypes.STRING(20), | ||
allowNull: true, | ||
}) | ||
await queryInterface.addColumn("centres", "vendor_identifier", { | ||
type: DataTypes.STRING(20), | ||
allowNull: true, | ||
}) | ||
await queryInterface.addColumn("centres", "is_first_nation_program", { | ||
type: DataTypes.BOOLEAN, | ||
allowNull: false, | ||
defaultValue: false, | ||
}) | ||
await queryInterface.addColumn("centres", "inspector_name", { | ||
type: DataTypes.STRING(100), | ||
allowNull: true, | ||
}) | ||
await queryInterface.addColumn("centres", "neighborhood", { | ||
type: DataTypes.STRING(100), | ||
allowNull: true, | ||
}) | ||
|
||
await queryInterface.addColumn("centres", "region", { | ||
type: DataTypes.STRING(100), | ||
allowNull: true, | ||
}) | ||
} | ||
|
||
export const down: Migration = async ({ context: queryInterface }) => { | ||
await queryInterface.removeColumn("centres", "licenseHolderName") | ||
await queryInterface.removeColumn("centres", "contactName") | ||
await queryInterface.removeColumn("centres", "physicalAddress") | ||
await queryInterface.removeColumn("centres", "mailingAddress") | ||
await queryInterface.removeColumn("centres", "email") | ||
await queryInterface.removeColumn("centres", "altEmail") | ||
await queryInterface.removeColumn("centres", "phoneNumber") | ||
await queryInterface.removeColumn("centres", "altPhoneNumber") | ||
await queryInterface.removeColumn("centres", "faxNumber") | ||
await queryInterface.removeColumn("centres", "vendorId") | ||
await queryInterface.removeColumn("centres", "isFirstNationProgram") | ||
await queryInterface.removeColumn("centres", "inspectorName") | ||
await queryInterface.removeColumn("centres", "neighborhood") | ||
await queryInterface.removeColumn("centres", "region") | ||
} |
23 changes: 23 additions & 0 deletions
23
api/src/db/migrations/2024.03.08T22.35.54.backfill-region-column-on-centres-table.ts
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,23 @@ | ||
import { DataTypes } from "sequelize" | ||
|
||
import type { Migration } from "@/db/umzug" | ||
|
||
export const up: Migration = async ({ context: queryInterface }) => { | ||
await queryInterface.sequelize.query(/* sql */ ` | ||
UPDATE centres | ||
SET region = 'whitehorse' | ||
WHERE region IS NULL | ||
`) | ||
|
||
await queryInterface.changeColumn("centres", "region", { | ||
type: DataTypes.STRING(100), | ||
allowNull: false, | ||
}) | ||
} | ||
|
||
export const down: Migration = async ({ context: queryInterface }) => { | ||
await queryInterface.changeColumn("centres", "region", { | ||
type: DataTypes.STRING(100), | ||
allowNull: true, | ||
}) | ||
} |
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
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.