SchemaProperties

import { MongooseParse } from '@appt/mongoose';

Remember the TSchema example above? The implementations of mongoose schemas can has a lot more straightforward approach using this helper. Let's see it:

import { Component } from '@appt/core';
import { TSchema, SchemaProperties } from '@appt/mongoose';
@Component({
extend: TSchema,
inject: SchemaProperties
})
export class AppShema {
constructor({
asString,
asBoolean,
asObjectId,
asNumber,
asDate,
asEnum
})
{
// Defaults: trim: true, default: ""
// telephones is a array of strings
this.telephones = [ asString() ];
// Defaults: default: 0
this.age = asNumber();
// Defaults: null
this.school = asObjectId();
// Defaults: default: false
this.active = asBoolean();
// Defaults: default: Date.now
this.created_at = asDate();
// Defaults: null
// Methods: ofStrings, ofNumbers, ofDates, ofBooleans, ofObjectIds
this.profile = asEnum({
default: 'student'
}).ofStrings([
'teacher',
'student'
]);
}
}