-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User defined id for
MeasurementPeriod
s
- Loading branch information
Showing
7 changed files
with
132 additions
and
6 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
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
23 changes: 23 additions & 0 deletions
23
src/proposals/dto/validators/unique-measurement-period-id.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 { | ||
ValidationArguments, | ||
ValidatorConstraint, | ||
ValidatorConstraintInterface, | ||
} from "class-validator"; | ||
import { MeasurementPeriodClass } from "src/proposals/schemas/measurement-period.schema"; | ||
|
||
@ValidatorConstraint({ async: false }) | ||
export class UniqueMeasurementPeriodIdConstraint | ||
implements ValidatorConstraintInterface | ||
{ | ||
validate( | ||
measurementPeriods: MeasurementPeriodClass[], | ||
args: ValidationArguments, | ||
) { | ||
const ids = measurementPeriods.map((period) => period.id); | ||
return ids.length === new Set(ids).size; | ||
} | ||
|
||
defaultMessage(args: ValidationArguments) { | ||
return "MeasurementPeriod id must be unique within the MeasurementPeriodList"; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,7 @@ const TestData = { | |
accessGroups: [], | ||
MeasurementPeriodList: [ | ||
{ | ||
id: "1", | ||
instrument: "ESS3-1", | ||
start: "2017-07-24T13:56:30.000Z", | ||
end: "2017-07-25T13:56:30.000Z", | ||
|
@@ -63,6 +64,29 @@ const TestData = { | |
], | ||
}, | ||
|
||
ProposalCorrectComplete2: { | ||
proposalId: "20170268", | ||
pi_email: "[email protected]", | ||
pi_firstname: "principal", | ||
pi_lastname: "investigator", | ||
email: "[email protected]", | ||
firstname: "proposal", | ||
lastname: "proposer", | ||
title: "A complete test proposal", | ||
abstract: "Abstract of test proposal", | ||
ownerGroup: "proposalingestor", | ||
accessGroups: [], | ||
MeasurementPeriodList: [ | ||
{ | ||
id: "1", | ||
instrument: "ESS3-1", | ||
start: "2017-07-24T13:56:30.000Z", | ||
end: "2017-07-25T13:56:30.000Z", | ||
comment: "Some comment", | ||
} | ||
], | ||
}, | ||
|
||
ProposalWrong_1: { | ||
proposalId: "20170267", | ||
pi_email: "[email protected]", | ||
|
@@ -79,6 +103,35 @@ const TestData = { | |
createdBy: "This should not be here", | ||
}, | ||
|
||
ProposalWrong_2: { | ||
proposalId: "20170267", | ||
pi_email: "[email protected]", | ||
pi_firstname: "principal", | ||
pi_lastname: "investigator", | ||
email: "[email protected]", | ||
firstname: "proposal", | ||
lastname: "proposer", | ||
title: "A complete test proposal with an extra field", | ||
abstract: "Abstract of test proposal", | ||
ownerGroup: "20170251-group", | ||
accessGroups: [], | ||
MeasurementPeriodList: [ | ||
{ | ||
id: "1", | ||
instrument: "ESS3-1", | ||
start: "2017-07-24T13:56:30.000Z", | ||
end: "2017-07-25T13:56:30.000Z", | ||
comment: "Some comment", | ||
}, | ||
{ | ||
id: "1", | ||
instrument: "ESS3-2", | ||
start: "2017-07-28T13:56:30.000Z", | ||
end: "2017-07-29T13:56:30.000Z", | ||
}, | ||
], | ||
}, | ||
|
||
AttachmentCorrect: { | ||
thumbnail: "data/abc123", | ||
caption: "Some caption", | ||
|