Skip to content

Instantly share code, notes, and snippets.

@bryzettler
Created October 15, 2018 14:20
Show Gist options
  • Save bryzettler/077cd57f777804a758603e0653bbaf46 to your computer and use it in GitHub Desktop.
Save bryzettler/077cd57f777804a758603e0653bbaf46 to your computer and use it in GitHub Desktop.
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