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

SIMSBIOHUB-345: Display Time in Sampling Periods #1167

Merged
merged 8 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,14 @@ POST.apiDoc = {
},
end_date: {
type: 'string'
},
start_time: {
type: 'string',
nullable: true
},
end_time: {
type: 'string',
nullable: true
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ PUT.apiDoc = {
},
end_date: {
type: 'string'
},
start_time: {
type: 'string',
nullable: true
},
end_time: {
type: 'string',
nullable: true
}
}
}
Expand Down
68 changes: 60 additions & 8 deletions api/src/repositories/sample-method-repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,22 @@ describe('SampleMethodRepository', () => {
method_lookup_id: 3,
description: 'description',
periods: [
{ end_date: '2023-01-02', start_date: '2023-10-02', survey_sample_method_id: 1, survey_sample_period_id: 4 },
{ end_date: '2023-10-03', start_date: '2023-11-05', survey_sample_method_id: 1, survey_sample_period_id: 5 }
{
end_date: '2023-01-02',
start_date: '2023-10-02',
start_time: '12:00:00',
end_time: '13:00:00',
survey_sample_method_id: 1,
survey_sample_period_id: 4
},
{
end_date: '2023-10-03',
start_date: '2023-11-05',
start_time: '12:00:00',
end_time: '13:00:00',
survey_sample_method_id: 1,
survey_sample_period_id: 5
}
]
};
const repo = new SampleMethodRepository(dbConnectionObj);
Expand All @@ -75,8 +89,22 @@ describe('SampleMethodRepository', () => {
method_lookup_id: 3,
description: 'description',
periods: [
{ end_date: '2023-01-02', start_date: '2023-10-02', survey_sample_method_id: 1, survey_sample_period_id: 4 },
{ end_date: '2023-10-03', start_date: '2023-11-05', survey_sample_method_id: 1, survey_sample_period_id: 5 }
{
end_date: '2023-01-02',
start_date: '2023-10-02',
start_time: '12:00:00',
end_time: '13:00:00',
survey_sample_method_id: 1,
survey_sample_period_id: 4
},
{
end_date: '2023-10-03',
start_date: '2023-11-05',
start_time: '12:00:00',
end_time: '13:00:00',
survey_sample_method_id: 1,
survey_sample_period_id: 5
}
]
};
const repo = new SampleMethodRepository(dbConnectionObj);
Expand All @@ -101,8 +129,20 @@ describe('SampleMethodRepository', () => {
method_lookup_id: 3,
description: 'description',
periods: [
{ end_date: '2023-01-02', start_date: '2023-10-02', survey_sample_method_id: 1 },
{ end_date: '2023-10-03', start_date: '2023-11-05', survey_sample_method_id: 1 }
{
end_date: '2023-01-02',
start_date: '2023-10-02',
start_time: '12:00:00',
end_time: '13:00:00',
survey_sample_method_id: 1
},
{
end_date: '2023-10-03',
start_date: '2023-11-05',
start_time: '12:00:00',
end_time: '13:00:00',
survey_sample_method_id: 1
}
]
};
const repo = new SampleMethodRepository(dbConnectionObj);
Expand All @@ -121,8 +161,20 @@ describe('SampleMethodRepository', () => {
method_lookup_id: 3,
description: 'description',
periods: [
{ end_date: '2023-01-02', start_date: '2023-10-02', survey_sample_method_id: 1 },
{ end_date: '2023-10-03', start_date: '2023-11-05', survey_sample_method_id: 1 }
{
end_date: '2023-01-02',
start_date: '2023-10-02',
start_time: '12:00:00',
end_time: '13:00:00',
survey_sample_method_id: 1
},
{
end_date: '2023-10-03',
start_date: '2023-11-05',
start_time: '12:00:00',
end_time: '13:00:00',
survey_sample_method_id: 1
}
]
};
const repo = new SampleMethodRepository(dbConnectionObj);
Expand Down
16 changes: 12 additions & 4 deletions api/src/repositories/sample-period-repository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ describe('SamplePeriodRepository', () => {
survey_sample_method_id: 1,
survey_sample_period_id: 2,
start_date: '2023-10-02',
end_date: '2023-01-02'
end_date: '2023-01-02',
start_time: '12:00:00',
end_time: '13:00:00'
};
const repo = new SamplePeriodRepository(dbConnectionObj);
const response = await repo.updateSamplePeriod(samplePeriod);
Expand All @@ -69,7 +71,9 @@ describe('SamplePeriodRepository', () => {
survey_sample_method_id: 1,
survey_sample_period_id: 2,
start_date: '2023-10-02',
end_date: '2023-01-02'
end_date: '2023-01-02',
start_time: '12:00:00',
end_time: '13:00:00'
};
const repo = new SamplePeriodRepository(dbConnectionObj);

Expand All @@ -91,7 +95,9 @@ describe('SamplePeriodRepository', () => {
const samplePeriod: InsertSamplePeriodRecord = {
survey_sample_method_id: 1,
start_date: '2023-10-02',
end_date: '2023-01-02'
end_date: '2023-01-02',
start_time: '12:00:00',
end_time: '13:00:00'
};
const repo = new SamplePeriodRepository(dbConnectionObj);
const response = await repo.insertSamplePeriod(samplePeriod);
Expand All @@ -107,7 +113,9 @@ describe('SamplePeriodRepository', () => {
const samplePeriod: InsertSamplePeriodRecord = {
survey_sample_method_id: 1,
start_date: '2023-10-02',
end_date: '2023-01-02'
end_date: '2023-01-02',
start_time: '12:00:00',
end_time: '13:00:00'
};
const repo = new SamplePeriodRepository(dbConnectionObj);

Expand Down
21 changes: 16 additions & 5 deletions api/src/repositories/sample-period-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import { getKnex } from '../database/db';
import { ApiExecuteSQLError } from '../errors/api-error';
import { BaseRepository } from './base-repository';

export type InsertSamplePeriodRecord = Pick<SamplePeriodRecord, 'survey_sample_method_id' | 'start_date' | 'end_date'>;
export type InsertSamplePeriodRecord = Pick<
SamplePeriodRecord,
'survey_sample_method_id' | 'start_date' | 'end_date' | 'start_time' | 'end_time'
>;

export type UpdateSamplePeriodRecord = Pick<
SamplePeriodRecord,
'survey_sample_period_id' | 'survey_sample_method_id' | 'start_date' | 'end_date'
'survey_sample_period_id' | 'survey_sample_method_id' | 'start_date' | 'end_date' | 'start_time' | 'end_time'
>;

// This describes a row in the database for Survey Sample Period
Expand All @@ -17,6 +20,8 @@ export const SamplePeriodRecord = z.object({
survey_sample_method_id: z.number(),
start_date: z.string(),
end_date: z.string(),
start_time: z.string().nullable(),
end_time: z.string().nullable(),
create_date: z.string(),
create_user: z.number(),
update_date: z.string().nullable(),
Expand Down Expand Up @@ -64,7 +69,9 @@ export class SamplePeriodRepository extends BaseRepository {
SET
survey_sample_method_id=${sample.survey_sample_method_id},
start_date=${sample.start_date},
end_date=${sample.end_date}
end_date=${sample.end_date},
start_time=${sample.start_time || null},
end_time=${sample.end_time || null}
WHERE
survey_sample_period_id = ${sample.survey_sample_period_id}
RETURNING
Expand Down Expand Up @@ -94,11 +101,15 @@ export class SamplePeriodRepository extends BaseRepository {
INSERT INTO survey_sample_period (
survey_sample_method_id,
start_date,
end_date
end_date,
start_time,
end_time
) VALUES (
${sample.survey_sample_method_id},
${sample.start_date},
${sample.end_date}
${sample.end_date},
${sample.start_time || null},
${sample.end_time || null}
)
RETURNING
*;`;
Expand Down
4 changes: 3 additions & 1 deletion api/src/services/sample-location-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ describe('SampleLocationService', () => {
{
survey_sample_method_id: 1,
start_date: '2023-01-01',
end_date: '2023-01-03'
end_date: '2023-01-03',
start_time: '12:00:00',
end_time: '13:00:00'
}
]
}
Expand Down
43 changes: 37 additions & 6 deletions api/src/services/sample-method-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ describe('SampleMethodService', () => {
survey_sample_period_id: 2,
start_date: '2023-10-04',
end_date: '2023-11-05',
start_time: '12:00:00',
end_time: '13:00:00',
create_date: '2023-01-02',
create_user: 1,
update_date: null,
Expand All @@ -145,8 +147,20 @@ describe('SampleMethodService', () => {
method_lookup_id: 3,
description: 'description',
periods: [
{ end_date: '2023-01-02', start_date: '2023-10-02', survey_sample_method_id: 1 },
{ end_date: '2023-10-03', start_date: '2023-11-05', survey_sample_method_id: 1 }
{
end_date: '2023-01-02',
start_date: '2023-10-02',
start_time: '12:00:00',
end_time: '13:00:00',
survey_sample_method_id: 1
},
{
end_date: '2023-10-03',
start_date: '2023-11-05',
start_time: '12:00:00',
end_time: '13:00:00',
survey_sample_method_id: 1
}
]
};
const sampleMethodService = new SampleMethodService(mockDBConnection);
Expand All @@ -156,12 +170,16 @@ describe('SampleMethodService', () => {
expect(insertSamplePeriodStub).to.be.calledWith({
survey_sample_method_id: mockSampleMethodRecord.survey_sample_method_id,
start_date: sampleMethod.periods[0].start_date,
end_date: sampleMethod.periods[0].end_date
end_date: sampleMethod.periods[0].end_date,
start_time: sampleMethod.periods[0].start_time,
end_time: sampleMethod.periods[0].end_time
});
expect(insertSamplePeriodStub).to.be.calledWith({
survey_sample_method_id: mockSampleMethodRecord.survey_sample_method_id,
start_date: sampleMethod.periods[1].start_date,
end_date: sampleMethod.periods[1].end_date
end_date: sampleMethod.periods[1].end_date,
start_time: sampleMethod.periods[1].start_time,
end_time: sampleMethod.periods[1].end_time
});
expect(response).to.eql(mockSampleMethodRecord);
});
Expand Down Expand Up @@ -201,8 +219,21 @@ describe('SampleMethodService', () => {
method_lookup_id: 3,
description: 'description',
periods: [
{ end_date: '2023-01-02', start_date: '2023-10-02', survey_sample_method_id: 1, survey_sample_period_id: 4 },
{ end_date: '2023-10-03', start_date: '2023-11-05', survey_sample_method_id: 1 } as SamplePeriodRecord
{
end_date: '2023-01-02',
start_date: '2023-10-02',
start_time: '12:00:00',
end_time: '13:00:00',
survey_sample_method_id: 1,
survey_sample_period_id: 4
},
{
end_date: '2023-10-03',
start_date: '2023-11-05',
start_time: '12:00:00',
end_time: '13:00:00',
survey_sample_method_id: 1
} as SamplePeriodRecord
]
};
const sampleMethodService = new SampleMethodService(mockDBConnection);
Expand Down
8 changes: 6 additions & 2 deletions api/src/services/sample-method-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ export class SampleMethodService extends DBService {
const samplePeriod = {
survey_sample_method_id: record.survey_sample_method_id,
start_date: item.start_date,
end_date: item.end_date
end_date: item.end_date,
start_time: item.start_time,
end_time: item.end_time
};
return samplePeriodService.insertSamplePeriod(samplePeriod);
});
Expand Down Expand Up @@ -134,7 +136,9 @@ export class SampleMethodService extends DBService {
const samplePeriod = {
survey_sample_method_id: sampleMethod.survey_sample_method_id,
start_date: item.start_date,
end_date: item.end_date
end_date: item.end_date,
start_time: item.start_time,
end_time: item.end_time
};
await samplePeriodService.insertSamplePeriod(samplePeriod);
}
Expand Down
Loading
Loading