Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE][LUCY-1169] - Add BlowBy table to capture BlowBy data coming from INSPECT #1170

Merged
merged 7 commits into from
Jan 25, 2024
54 changes: 54 additions & 0 deletions api/api_sources/schema-files/blowBy.schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
version: '1.0'
description: Schema file for table blow_by
externalTables: []
includes:
- observerWorkflow.schema.yaml
schemas:
BlowBySchema:
name: blow_by
description: 'Table to store blow by data for watercraft observer.'
baseSchema: RecordSchema
meta:
resource: true
api: /mussels/blow-bys
base: api
resource: true
baseModel: Record
columns:
id:
name: blow_by_id
comment: Auto generated primary key
definition: SERIAL PRIMARY KEY
observerWorkflowId:
name: observer_workflow_id
comment: Foreign key to observer_workflow
definition: INT NULL
foreignTable: observer_workflow
refColumn: observer_workflow_id
blowByTime:
name: blow_by_time
comment: Time of blow by
definition: TIMESTAMP NULL
watercraftComplexity:
name: watercraft_complexity
comment: Watercraft complexity
definition: VARCHAR(100) NULL
reportedToRapp:
name: reported_to_rapp
comment: Reported to rapp
definition: BOOLEAN NOT NULL DEFAULT false
relations:
observerWorkflow:
header:
key: blow_by.observer_workflow
default: Observer Workflow
description:
key: blow_by.observer_workflow.description
default: Observer workflow associated with the blow by
type: single
relationshipType: many-to-one
schema: ObserverWorkflowSchema
meta:
skipValidation: true
versions: []
fields: {}
41 changes: 41 additions & 0 deletions api/api_sources/schema-migration-sql/BlowBySchema/BlowBySchema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
-- ### Creating Table: blow_by ### --


CREATE TABLE blow_by ();
ALTER TABLE blow_by ADD COLUMN blow_by_id SERIAL PRIMARY KEY;
ALTER TABLE blow_by ADD COLUMN observer_workflow_id INT NULL REFERENCES observer_workflow(observer_workflow_id) ON DELETE SET NULL;
ALTER TABLE blow_by ADD COLUMN blow_by_time TIMESTAMP NULL;
ALTER TABLE blow_by ADD COLUMN watercraft_complexity VARCHAR(100) NULL;
ALTER TABLE blow_by ADD COLUMN reported_to_rapp BOOLEAN NOT NULL DEFAULT false;



-- ### Creating Comments on table ### --


COMMENT ON TABLE blow_by IS 'Table to store blow by data for watercraft observer.';
COMMENT ON COLUMN blow_by.blow_by_id IS 'Auto generated primary key';
COMMENT ON COLUMN blow_by.observer_workflow_id IS 'Foreign key to observer_workflow';
COMMENT ON COLUMN blow_by.blow_by_time IS 'Time of blow by';
COMMENT ON COLUMN blow_by.watercraft_complexity IS 'Watercraft complexity';
COMMENT ON COLUMN blow_by.reported_to_rapp IS 'Reported to rapp';



-- ### Creating Timestamp column ### --


ALTER TABLE blow_by ADD COLUMN created_at TIMESTAMP DEFAULT NOW();
ALTER TABLE blow_by ADD COLUMN updated_at TIMESTAMP DEFAULT NOW();
COMMENT ON COLUMN blow_by.created_at IS 'Timestamp column to check creation time of record';
COMMENT ON COLUMN blow_by.updated_at IS 'Timestamp column to check modify time of record';


-- ### Creating User Audit Columns ### --


ALTER TABLE blow_by ADD COLUMN updated_by_user_id INT NULL DEFAULT NULL REFERENCES application_user(user_id) ON DELETE SET NULL;
ALTER TABLE blow_by ADD COLUMN created_by_user_id INT NULL DEFAULT NULL REFERENCES application_user(user_id) ON DELETE SET NULL;
COMMENT ON COLUMN blow_by.updated_by_user_id IS 'Audit column to track creator';
COMMENT ON COLUMN blow_by.created_by_user_id IS 'Audit column to track modifier';
-- ### End: blow_by ### --
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,9 @@ export class AdultMusselsLocationSchema extends RecordTableSchema {
return true;
}
}

export class BlowBySchema extends RecordTableSchema {
get schemaFilePath(): string {
return getYAMLFilePath('blowBy.schema.yaml');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {MigrationInterface, QueryRunner} from 'typeorm';
import { AppDBMigrator } from '../applicationSchemaInterface';
import { BlowBySchema, ObserverWorkflowSchema } from '../database-schema';

export class CreateBlowBy1703888022971 extends AppDBMigrator implements MigrationInterface {
blowBySchema: BlowBySchema;
observerWorkflowSchema: ObserverWorkflowSchema;

/**
* Setup
*/
setup() {
// Adding BlowBy schema to migrator
this.blowBySchema = new BlowBySchema();
this.observerWorkflowSchema = new ObserverWorkflowSchema();

// Create BlowBy table
this.addSchemaInitVersion(this.blowBySchema);
}

/**
* UP: Create DB method
*/
public async up(queryRunner: QueryRunner): Promise<any> {
// Start Log
this.log('[START]', 'UP');
// Running all up migration files
await this.runQuerySqlFiles(this.upMigrations(), queryRunner);
this.log('[END]', 'UP');
}

/**
* Down: Revert
*/
public async down(queryRunner: QueryRunner): Promise<any> {
this.log('[START]', 'DOWN');
await queryRunner.query(this.blowBySchema.dropTable());
await queryRunner.query(this.observerWorkflowSchema.dropTable());
this.log('[END]', 'DOWN');
}

}
90 changes: 90 additions & 0 deletions api/api_sources/sources/database/models/blowBy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// ** Model: BlowBy from schema BlowBySchema **

import { Column, Entity, PrimaryGeneratedColumn, JoinColumn, ManyToOne } from 'typeorm';
import { BlowBySchema, ObserverWorkflowSchema } from '../database-schema';
import {
} from '../database-schema';

davidclaveau marked this conversation as resolved.
Show resolved Hide resolved
import { ModelProperty, PropertyType, ModelDescription } from '../../libs/core-model';
import { ObserverWorkflow, Record } from '../models';
import { DateTimeTransformer } from '../../libs/transformer';

/** Interface **/
/**
* @description BlowBy create interface
*/
export interface BlowBySpec {
observerWorkflowId: ObserverWorkflow;
blowByTime: string;
watercraftComplexity: string;
reportedToRapp: boolean;
}
// -- End: BlowBySpec --


/** Interface **/
/**
* @description BlowBy update interface
*/
export interface BlowByUpdateSpec {
observerWorkflowId?: ObserverWorkflow;
blowByTime?: string;
watercraftComplexity?: string;
reportedToRapp?: boolean;
}
// -- End: BlowByUpdateSpec --

/**
* @description Data Model Class for BlowBySchema
*/
@ModelDescription({
description: 'Data Model Class for BlowBySchema',
schema: BlowBySchema,
apiResource: false
})
@Entity( { name: BlowBySchema.dbTable} )
export class BlowBy extends Record implements BlowBySpec {

/**
* Class Properties
*/

/**
* @description Getter/Setter property for column {blow_by_id}
*/
@PrimaryGeneratedColumn()
@ModelProperty({type: PropertyType.number})
blow_by_id: number;

/**
* @description Getter/Setter property for column {observer_workflow_id}
*/
@ManyToOne( type => ObserverWorkflow, { eager: true})
@JoinColumn({ name: BlowBySchema.columns.observerWorkflowId, referencedColumnName: ObserverWorkflowSchema.pk})
@ModelProperty({type: PropertyType.object})
observerWorkflowId: ObserverWorkflow;

/**
* @description Getter/Setter property for column {blow_by_time}
*/
@Column({ name: BlowBySchema.columns.blowByTime, transformer: new DateTimeTransformer()})
@ModelProperty({type: PropertyType.string})
blowByTime: string;

/**
* @description Getter/Setter property for column {watercraft_complexity}
*/
@Column({ name: BlowBySchema.columns.watercraftComplexity})
@ModelProperty({type: PropertyType.string})
watercraftComplexity: string;

/**
* @description Getter/Setter property for column {reported_to_rapp}
*/
@Column({ name: BlowBySchema.columns.reportedToRapp})
@ModelProperty({type: PropertyType.boolean})
reportedToRapp: boolean;

}

// -------------------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// ** BlowByController ** //

import { RecordController } from '../generic.data.models';
import { BlowBy} from '../../models';
import { BlowBySchema } from '../../database-schema';

// ** BlowByController ** //


/**
* @description Data Model Controller Class for BlowBySchema and BlowBy
*/
export class BlowByController extends RecordController<BlowBy> {
/**
* @description Getter for shared instance
*/
public static get shared(): BlowByController {
return this.sharedInstance<BlowBy>(BlowBy, BlowBySchema) as BlowByController;
}

public async all(query?: any): Promise<BlowBy[]> {
const options = query || {};
options.relations = ['observerWorkflowId'];
return await this.repo.find(options) as BlowBy[];
}

get exportKeyPriorities(): {[key: string]: number} {
const basePriority = 1000;
const topPriority = 100;
return {
id: basePriority + topPriority,
observerWorkflowId: (basePriority + topPriority - 10),
blowByTime: (basePriority + topPriority - 50),
watercraftComplexity: (basePriority + topPriority - 60),
reportedToRapp: (basePriority + topPriority - 70),
};
}

processForExport(data: BlowBy): any {
const result: any = {};
Object.keys(data).forEach((key) => {
if (this.exportKeyMapper[key]) {
result[this.exportKeyMapper[key]] = data[key];
}
});
return result;
}
}
// ----------------
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ export class WatercraftRiskAssessmentController extends RecordController<Watercr
result.shiftEndTime = `${workflow.endTime}`;
result.k9OnShift = `${workflow.k9OnShift}`;
result.motorizedBlowBys = workflow.motorizedBlowBys;
result.noBoatInspected = false;
result.nonMotorizedBlowBys = workflow.nonMotorizedBlowBys;
result.noBoatInspected = false;
result.shiftStartComment = workflow.shiftStartComment;
result.shiftEndComment = workflow.shiftEndComment;

Expand Down
2 changes: 2 additions & 0 deletions api/api_sources/sources/database/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export * from './behaviourCode';
export * from './animalSpecies';
export * from './animalObservation';
export * from './majorCity';
export * from './blowBy';

/**
* Controllers
Expand Down Expand Up @@ -107,4 +108,5 @@ export * from './controllers/watercraftJourney.controller';
export * from './controllers/seed.controller';
export * from './controllers/animalObservation.controller';
export * from './controllers/majorCity.controller';
export * from './controllers/blowBy.controller';
// ----------------------------------------------------------------------------------------------------------------
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Column, Entity, PrimaryGeneratedColumn} from 'typeorm';
import { ObserverWorkflowSchema } from '../database-schema';

import { ModelProperty, PropertyType, ModelDescription } from '../../libs/core-model';
import { IntTransformer, DateTransformer, DateTimeTransformer } from '../../libs/transformer';
import { DateTransformer, DateTimeTransformer, IntTransformer } from '../../libs/transformer';
import { Record } from './generic.data.models';

/** Interface **/
Expand Down
4 changes: 4 additions & 0 deletions api/api_sources/sources/server/initializers/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { accountRoute,
import { LocationRouteController } from '../modules/location';
import { BCGeoDataRouteController } from '../modules/bcGeoData';
import { defaultRoute, miscellaneousRouter } from '../modules';
import { BlowByRouteController } from '../modules/blowBy';

/**
* @description Configuring main app routes
Expand Down Expand Up @@ -80,6 +81,9 @@ export const routes = (app: Application) => {
// Observer Workflow
app.use('/api/mussels/workflow', ObserverWorkflowRouteController.shared.router);

// Watercraft Risk Assessment
app.use('/api/mussels/blow-bys', BlowByRouteController.shared.router);

// Mussels App Codes
app.use('/api/mussels/codes', MusselsAppCodesRouteController.shared.router);

Expand Down
Loading