Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into sampling-container
Browse files Browse the repository at this point in the history
  • Loading branch information
NickPhura committed Nov 22, 2024
2 parents 43cdb7f + 9f51398 commit 30a3c14
Show file tree
Hide file tree
Showing 204 changed files with 9,415 additions and 2,308 deletions.
27 changes: 24 additions & 3 deletions api/.pipeline/templates/api.dc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ parameters:
description: S3 key optional prefix
required: false
value: 'sims'
# Request limits
- name: MAX_REQ_BODY_SIZE
description: Maximum request body size in bytes
value: '52428800'
- name: MAX_UPLOAD_NUM_FILES
description: Maximum number of files uploaded in a single request
value: '10'
- name: MAX_UPLOAD_FILE_SIZE
description: Maximum upload file size in bytes
value: '52428800'
# Logging
- name: LOG_LEVEL
value: 'silent'
Expand Down Expand Up @@ -162,12 +172,12 @@ parameters:
- name: GCNOTIFY_ONBOARDING_REQUEST_EMAIL_TEMPLATE
description: gcnotify email template id
value: 7779a104-b863-40ac-902f-1aa607d2071a
- name: GCNOTIFY_REQUEST_RESUBMIT_TEMPLATE
description: gcnotify email resubmit template id
value: c973da33-1f2b-435a-9429-d8ab4fd273c5
- name: GCNOTIFY_ONBOARDING_REQUEST_SMS_TEMPLATE
description: gcnotify sms template id
value: af2f1e40-bd72-4612-9c5a-567ee5b26ca5
- name: GCNOTIFY_REQUEST_RESUBMIT_TEMPLATE
description: gcnotify request resubmit email template
value: c973da33-1f2b-435a-9429-d8ab4fd273c5
- name: GCNOTIFY_EMAIL_URL
value: https://api.notification.canada.ca/v2/notifications/email
- name: GCNOTIFY_SMS_URL
Expand Down Expand Up @@ -336,6 +346,13 @@ objects:
value: ${KEYCLOAK_API_HOST}
- name: KEYCLOAK_API_ENVIRONMENT
value: ${KEYCLOAK_API_ENVIRONMENT}
# Request limits
- name: MAX_REQ_BODY_SIZE
value: ${MAX_REQ_BODY_SIZE}
- name: MAX_UPLOAD_NUM_FILES
value: ${MAX_UPLOAD_NUM_FILES}
- name: MAX_UPLOAD_FILE_SIZE
value: ${MAX_UPLOAD_FILE_SIZE}
# Object Store (S3)
- name: OBJECT_STORE_URL
valueFrom:
Expand All @@ -357,6 +374,8 @@ objects:
secretKeyRef:
key: object_store_bucket_name
name: ${OBJECT_STORE_SECRETS}
- name: S3_KEY_PREFIX
value: ${S3_KEY_PREFIX}
# Logging
- name: LOG_LEVEL
value: ${LOG_LEVEL}
Expand Down Expand Up @@ -387,6 +406,8 @@ objects:
value: ${GCNOTIFY_ADMIN_EMAIL}
- name: GCNOTIFY_ONBOARDING_REQUEST_EMAIL_TEMPLATE
value: ${GCNOTIFY_ONBOARDING_REQUEST_EMAIL_TEMPLATE}
- name: GCNOTIFY_REQUEST_RESUBMIT_TEMPLATE
value: ${GCNOTIFY_REQUEST_RESUBMIT_TEMPLATE}
- name: GCNOTIFY_ONBOARDING_REQUEST_SMS_TEMPLATE
value: ${GCNOTIFY_ONBOARDING_REQUEST_SMS_TEMPLATE}
- name: GCNOTIFY_EMAIL_URL
Expand Down
12 changes: 8 additions & 4 deletions api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,24 @@ import {
} from './middleware/critterbase-proxy';
import { rootAPIDoc } from './openapi/root-api-doc';
import { authenticateRequest, authenticateRequestOptional } from './request-handlers/security/authentication';
import { loadEvironmentVariables } from './utils/env-config';
import { scanFileForVirus } from './utils/file-utils';
import { getLogger } from './utils/logger';

// Load and validate the environment variables
loadEvironmentVariables();

const defaultLog = getLogger('app');

const HOST = process.env.API_HOST;
const PORT = Number(process.env.API_PORT);
const PORT = process.env.API_PORT;

// Max size of the body of the request (bytes)
const MAX_REQ_BODY_SIZE = Number(process.env.MAX_REQ_BODY_SIZE) || 52428800;
const MAX_REQ_BODY_SIZE = process.env.MAX_REQ_BODY_SIZE;
// Max number of files in a single request
const MAX_UPLOAD_NUM_FILES = Number(process.env.MAX_UPLOAD_NUM_FILES) || 10;
const MAX_UPLOAD_NUM_FILES = process.env.MAX_UPLOAD_NUM_FILES;
// Max size of a single file (bytes)
const MAX_UPLOAD_FILE_SIZE = Number(process.env.MAX_UPLOAD_FILE_SIZE) || 52428800;
const MAX_UPLOAD_FILE_SIZE = process.env.MAX_UPLOAD_FILE_SIZE;

// Get initial express app
const app: express.Express = express();
Expand Down
22 changes: 22 additions & 0 deletions api/src/constants/dates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Date formats.
*
* See BC Gov standards: https://www2.gov.bc.ca/gov/content/governments/services-for-government/policies-procedures/web-content-development-guides/writing-for-the-web/web-style-guide/numbers
*/
export const DefaultDateFormat = 'YYYY-MM-DD'; // 2020-01-05

export const DefaultDateFormatReverse = 'DD-MM-YYYY'; // 05-01-2020

export const AltDateFormat = 'YYYY/MM/DD'; // 2020/01/05

export const AltDateFormatReverse = 'DD/MM/YYYY'; // 05/01/2020

/*
* Time formats.
*/
export const DefaultTimeFormat = 'HH:mm:ss'; // 23:00:00

/*
* Datetime formats.
*/
export const DefaultDateTimeFormat = `${DefaultDateFormat}T${DefaultTimeFormat}`; // 2020-01-05T23:00:00
8 changes: 4 additions & 4 deletions api/src/database/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ import { asyncErrorWrapper, getGenericizedKeycloakUserInformation, syncErrorWrap
const defaultLog = getLogger('database/db');

const getDbHost = () => process.env.DB_HOST;
const getDbPort = () => Number(process.env.DB_PORT);
const getDbPort = () => process.env.DB_PORT;
const getDbUsername = () => process.env.DB_USER_API;
const getDbPassword = () => process.env.DB_USER_API_PASS;
const getDbDatabase = () => process.env.DB_DATABASE;

const DB_POOL_SIZE: number = Number(process.env.DB_POOL_SIZE) || 20;
const DB_CONNECTION_TIMEOUT: number = Number(process.env.DB_CONNECTION_TIMEOUT) || 0;
const DB_IDLE_TIMEOUT: number = Number(process.env.DB_IDLE_TIMEOUT) || 10000;
const DB_POOL_SIZE = 20;
const DB_CONNECTION_TIMEOUT = 0;
const DB_IDLE_TIMEOUT = 10000;

export const DB_CLIENT = 'pg';

Expand Down
29 changes: 29 additions & 0 deletions api/src/models/alert-view.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { z } from 'zod';

// Define the alert schema
export const IAlert = z.object({
alert_id: z.number(),
alert_type_id: z.number().int(),
name: z.string(),
message: z.string(),
severity: z.enum(['info', 'success', 'error', 'warning']),
data: z.object({}).nullable(),
record_end_date: z.string().nullable(),
status: z.enum(['active', 'expired'])
});

// Infer types from the schema
export type IAlert = z.infer<typeof IAlert>;
export type IAlertCreateObject = Omit<IAlert, 'alert_id' | 'status'>;
export type IAlertUpdateObject = Omit<IAlert, 'status'>;

// Filter object for viewing alerts
export interface IAlertFilterObject {
expiresBefore?: string;
expiresAfter?: string;
types?: string[];
}

// Define severity and status types
export type IAlertSeverity = 'info' | 'success' | 'error' | 'warning';
export type IAlertStatus = 'active' | 'expired';
2 changes: 1 addition & 1 deletion api/src/models/project-survey-attachments.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { default as dayjs } from 'dayjs';
import dayjs from 'dayjs';
import { ATTACHMENT_TYPE } from '../constants/attachments';
import { getLogger } from '../utils/logger';
import { SurveySupplementaryData } from './survey-view';
Expand Down
19 changes: 19 additions & 0 deletions api/src/models/sampling-locations-view.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export interface ISiteAdvancedFilters {
survey_id?: number;
keyword?: string;
system_user_id?: number;
}

export interface IMethodAdvancedFilters {
survey_id?: number;
sample_site_id?: number;
keyword?: string;
system_user_id?: number;
}

export interface IPeriodAdvancedFilters {
survey_id?: number;
sample_site_id?: number;
sample_method_id?: number;
system_user_id?: number;
}
83 changes: 83 additions & 0 deletions api/src/openapi/schemas/alert.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { OpenAPIV3 } from 'openapi-types';

/**
* Base schema for system alerts
*/
const baseSystemAlertSchema: OpenAPIV3.SchemaObject = {
type: 'object',
description: 'Schema defining alerts created by system administrators.',
additionalProperties: false,
properties: {
name: {
description: 'Name to display as the title of the alert',
type: 'string'
},
message: {
description: 'Message to display on the alert',
type: 'string'
},
alert_type_id: {
description: 'Type of the alert, controlling how it is displayed.',
type: 'number'
},
severity: {
description: 'Severity level of the alert',
type: 'string',
enum: ['info', 'success', 'warning', 'error']
},
data: {
description: 'Data associated with the alert',
type: 'object',
nullable: true
},
record_end_date: {
description: 'End date of the alert',
type: 'string',
nullable: true
}
}
};

/**
* Schema for updating system alerts
*/
export const systemAlertPutSchema: OpenAPIV3.SchemaObject = {
...baseSystemAlertSchema,
required: ['alert_id', 'name', 'message', 'data', 'alert_type_id', 'record_end_date', 'severity'],
additionalProperties: false,
properties: {
...baseSystemAlertSchema.properties,
alert_id: {
type: 'integer',
minimum: 1,
description: 'Primary key of the alert'
}
}
};

/**
* Schema for getting system alerts
*/
export const systemAlertGetSchema: OpenAPIV3.SchemaObject = {
...baseSystemAlertSchema,
required: ['alert_id', 'name', 'message', 'data', 'alert_type_id', 'record_end_date', 'severity', 'status'],
additionalProperties: false,
properties: {
...systemAlertPutSchema.properties,
status: {
type: 'string',
enum: ['active', 'expired'],
description:
'Status of the alert based on comparing the current date to record_end_date, calculated in the get query.'
}
}
};

/**
* Schema for creating system alerts
*/
export const systemAlertCreateSchema: OpenAPIV3.SchemaObject = {
...baseSystemAlertSchema,
additionalProperties: false,
required: ['name', 'message', 'data', 'alert_type_id', 'record_end_date', 'severity']
};
23 changes: 17 additions & 6 deletions api/src/openapi/schemas/observation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { OpenAPIV3 } from 'openapi-types';
import { paginationResponseSchema } from './pagination';
import { SampleLocationSchema } from './sample-site';

export const observervationsWithSubcountDataSchema: OpenAPIV3.SchemaObject = {
type: 'object',
Expand Down Expand Up @@ -60,19 +61,27 @@ export const observervationsWithSubcountDataSchema: OpenAPIV3.SchemaObject = {
nullable: true
},
latitude: {
type: 'number'
type: 'number',
nullable: true,
minimum: -90,
maximum: 90
},
longitude: {
type: 'number'
type: 'number',
nullable: true,
minimum: -180,
maximum: 180
},
count: {
type: 'integer'
},
observation_date: {
type: 'string'
type: 'string',
nullable: true
},
observation_time: {
type: 'string'
type: 'string',
nullable: true
},
survey_sample_site_name: {
type: 'string',
Expand Down Expand Up @@ -217,7 +226,8 @@ export const observervationsWithSubcountDataSchema: OpenAPIV3.SchemaObject = {
'qualitative_measurements',
'quantitative_measurements',
'qualitative_environments',
'quantitative_environments'
'quantitative_environments',
'sample_sites'
],
properties: {
observationCount: {
Expand Down Expand Up @@ -404,7 +414,8 @@ export const observervationsWithSubcountDataSchema: OpenAPIV3.SchemaObject = {
}
}
}
}
},
sample_sites: SampleLocationSchema
}
},
pagination: { ...paginationResponseSchema }
Expand Down
Loading

0 comments on commit 30a3c14

Please sign in to comment.