Created
October 15, 2018 14:20
-
-
Save bryzettler/077cd57f777804a758603e0653bbaf46 to your computer and use it in GitHub Desktop.
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
import { format, addDays, differenceInDays } from 'date-fns'; | |
import BaseModel from './BaseModel'; | |
export default class Milestone extends BaseModel { | |
static tableName = 'Milestones'; | |
static tracker = true; | |
static timestamps = true; | |
static auditKeys = ['isComplete', 'startDate', 'endDate', 'name', 'status', 'parentMilestoneId']; | |
static jsonSchema = { | |
type: 'object', | |
properties: { | |
id: { type: ['integer', 'string', 'null'] }, | |
projectId: { type: ['integer', 'string'] }, | |
parentMilestoneId: { type: ['integer', 'string', 'null'] }, | |
type: { | |
anyOf: [ | |
{ type: 'string', minLength: 1, maxLength: 255 }, | |
{ type: null }, | |
], | |
}, | |
name: { type: 'string', minLength: 1, maxLength: 255 }, | |
order: { type: ['string', 'integer', 'null'] }, | |
startDate: { type: ['string', 'null'] }, | |
endDate: { type: ['string', 'null'] }, | |
isComplete: { type: ['boolean', 'null'] }, | |
status: { type: ['string', 'null'] }, | |
createdBy: { type: ['string', 'integer', 'null'] }, | |
updatedBy: { type: ['string', 'integer', 'null'] }, | |
createdAt: { type: 'string' }, | |
updatedAt: { tyep: 'string' }, | |
}, | |
}; | |
static auditSanitize = modelObj => ({ | |
...modelObj, | |
...(modelObj.startDate && { startDate: format(new Date(modelObj.startDate), 'YYYY-MM-DD') }), | |
...(modelObj.endDate && { endDate: format(new Date(modelObj.endDate), 'YYYY-MM-DD') }), | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment