Skip to content

Commit

Permalink
Add the ageBuckets reference to mongoose schema #2670
Browse files Browse the repository at this point in the history
  • Loading branch information
iamleeg committed Apr 20, 2022
1 parent 56baa76 commit 573e256
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
22 changes: 22 additions & 0 deletions data-serving/data-service/src/model/age-bucket.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Range } from './range';
import mongoose from 'mongoose';

export const ageBucketSchema = new mongoose.Schema({
start: {
type: Number,
min: 0,
max: 116,
},
end: {
type: Number,
min: 0,
max: 120,
},
});

export type AgeBucketDocument = mongoose.Document & Range<number>;

export const AgeBuckets = mongoose.model<AgeBucketDocument>(
'AgeBuckets',
ageBucketSchema,
);
12 changes: 12 additions & 0 deletions data-serving/data-service/src/model/demographics.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import { Range } from './range';
import mongoose from 'mongoose';
import { ObjectId } from 'mongodb';

export const demographicsSchema = new mongoose.Schema(
{
/*
* The idea is that the age buckets are an enumeration supplied in the database,
* so you can refer to them here in the ageBuckets collection but you shouldn't
* make up your own age ranges.
*
* A case can belong to zero age buckets if it didn't specify an age, and more
* than one age bucket if the age range specified in the case overlapped more
* than one of the buckets we use.
*/
ageBuckets: [{ type: mongoose.Schema.Types.ObjectId, ref: 'ageBuckets' }],
ageRange: {
start: {
type: Number,
Expand All @@ -25,6 +36,7 @@ export const demographicsSchema = new mongoose.Schema(
);

export type DemographicsDocument = mongoose.Document & {
ageBuckets: ObjectId[];
ageRange: Range<number>;
gender: string;
occupation: string;
Expand Down

0 comments on commit 573e256

Please sign in to comment.