Skip to content

Commit

Permalink
fix: merged dev
Browse files Browse the repository at this point in the history
  • Loading branch information
MacQSL committed Jan 21, 2025
2 parents 898e7c4 + 2e53ed5 commit 5c73943
Show file tree
Hide file tree
Showing 38 changed files with 1,717 additions and 6,262 deletions.
2,959 changes: 995 additions & 1,964 deletions api/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"uuid": "^8.3.2",
"winston": "^3.3.3",
"winston-daily-rotate-file": "^5.0.0",
"xlsx": "https://cdn.sheetjs.com/xlsx-0.19.3/xlsx-0.19.3.tgz",
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz",
"zod": "^3.23.8"
},
"devDependencies": {
Expand Down
24 changes: 24 additions & 0 deletions api/src/__mocks__/xlsx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import xlsx from 'xlsx';
import { DEFAULT_XLSX_SHEET_NAME } from '../utils/xlsx-utils/worksheet-utils';

/**
* Returns a mock XLSX workbook buffer.
*
* Note: The keys of the record will be used as the worksheet headers.
*
* @param {Record<string, any>[]} data The data to inject into the workbook.
* @return {*} {Buffer}
*/
export const getMockXLSXWorkbookBuffer = (data: Record<string, any>[]): Buffer => {
// Create a new empty workbook
const workbook = xlsx.utils.book_new();

// Create a new worksheet with the array of records
const worksheet = xlsx.utils.json_to_sheet(data);

// Inject the worksheet data into the workbook with the default name
xlsx.utils.book_append_sheet(workbook, worksheet, DEFAULT_XLSX_SHEET_NAME);

// Convert the workbook to a xlsx buffer
return xlsx.write(workbook, { bookType: 'xlsx', type: 'buffer' });
};
16 changes: 12 additions & 4 deletions api/src/constants/dates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@
*
* 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 DefaultDateFormat = 'YYYY-MM-DD'; // 2020-01-15

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

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

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

export const USDefaultDateFormat = 'YYYY-DD-MM'; // 2020-15-01

export const USDefaultDateFormatReverse = 'MM-DD-YYYY'; // 01-15-2020

export const USAltDateFormat = 'MM/DD/YYYY'; // 01/15/2020

export const USAltDateFormatReverse = 'YYYY/DD/MM'; // 2020/15/01

/*
* Time formats.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe('getSurveyCritter', () => {

expect(mockRes.status).to.have.been.calledWith(200);
expect(mockRes.json).to.have.been.calledWith({
attachments: mockAttachments,
attachments: { capture_attachments: mockAttachments.captureAttachments },
...mockCritterbaseCritter,
...mockSimsCritter
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ GET.apiDoc = {
type: 'object',
description:
'Attachments associated with the critter. Only included if requested via the expand query parameter.',
required: ['captureAttachments'],
required: ['capture_attachments'],
properties: {
capture_attachments: {
type: 'array',
Expand Down Expand Up @@ -310,7 +310,7 @@ export function getSurveyCritter(): RequestHandler {
? critterAttachmentService.findAllCritterAttachments(surveyCritter.critter_id).then((response) => {
return {
attachments: {
captureAttachments: response.captureAttachments
capture_attachments: response.captureAttachments
// TODO: add mortality attachments
}
};
Expand Down
8 changes: 5 additions & 3 deletions api/src/repositories/standards-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,18 @@ export class StandardsRepository extends BaseRepository {
taq.description AS qual_description,
COALESCE(json_agg(
json_build_object(
'name', mlaqo.name,
'description', mlaqo.description
) ORDER BY mlaqo.name
'name', taqo.name,
'description', taqo.description
) ORDER BY taqo.name
), '[]'::json) AS options
FROM
method_lookup_attribute_qualitative_option mlaqo
LEFT JOIN
method_lookup_attribute_qualitative mlaq ON mlaqo.method_lookup_attribute_qualitative_id = mlaq.method_lookup_attribute_qualitative_id
LEFT JOIN
technique_attribute_qualitative taq ON mlaq.technique_attribute_qualitative_id = taq.technique_attribute_qualitative_id
LEFT JOIN
technique_attribute_qualitative_option taqo ON taqo.technique_attribute_qualitative_option_id = mlaqo.technique_attribute_qualitative_option_id
GROUP BY
mlaq.method_lookup_id,
taq.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ describe('TelemetryHeaderConfigs', () => {
const result = cellValidator({ cell: 5555 } as CSVParams);
expect(result).to.deep.equal([
{
error: 'Device not found in the survey deployments',
solution: 'Check the serial number and vendor are correct and the device is deployed in the survey'
error: 'Device not found in deployments',
solution: 'Check that the serial number and vendor match a deployment in the Survey'
}
]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export const getTelemetrySerialCellValidator = (
if (!deployment) {
return [
{
error: `Device not found in the survey deployments`,
solution: `Check the serial number and vendor are correct and the device is deployed in the survey`
error: `Device not found in deployments`,
solution: `Check that the serial number and vendor match a deployment in the Survey`
}
];
}
Expand Down
6 changes: 3 additions & 3 deletions api/src/utils/csv-utils/csv-config-validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('csv-config-validation', () => {
errors: [
{
error: 'A required column is missing',
solution: `Add all required columns to the file.`,
solution: `Add the ALIAS column to the file.`,
header: 'ALIAS',
values: ['ALIAS', 'ALIAS_2'],
cell: null,
Expand Down Expand Up @@ -217,7 +217,7 @@ describe('csv-config-validation', () => {
{
row: 1,
error: 'A required column is missing',
solution: `Add all required columns to the file.`,
solution: `Add the ALIAS column to the file.`,
header: 'ALIAS',
values: ['ALIAS'],
cell: null
Expand Down Expand Up @@ -247,7 +247,7 @@ describe('csv-config-validation', () => {
{
row: 1,
error: 'An unknown column is included in the file',
solution: `Remove extra columns from the file.`,
solution: `Remove the UNKNOWN_HEADER column from the file.`,
header: 'UNKNOWN_HEADER',
cell: null,
values: null
Expand Down
4 changes: 2 additions & 2 deletions api/src/utils/csv-utils/csv-config-validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export const validateCSVHeaders = (worksheet: WorkSheet, config: CSVConfig): Req
if (!headerConfig.optional && !worksheetHasStaticHeader) {
csvErrors.push({
error: 'A required column is missing',
solution: `Add all required columns to the file.`,
solution: `Add the ${staticHeader} column to the file.`,
values: [staticHeader, ...config.staticHeadersConfig[staticHeader].aliases],
header: staticHeader,
cell: null,
Expand All @@ -137,7 +137,7 @@ export const validateCSVHeaders = (worksheet: WorkSheet, config: CSVConfig): Req
for (const unknownHeader of configUtils.worksheetDynamicHeaders) {
csvErrors.push({
error: 'An unknown column is included in the file',
solution: `Remove extra columns from the file.`,
solution: `Remove the ${unknownHeader} column from the file.`,
values: null,
header: unknownHeader,
cell: null,
Expand Down
Loading

0 comments on commit 5c73943

Please sign in to comment.