initial commit
This commit is contained in:
commit
32b5df8c22
10 changed files with 1749 additions and 0 deletions
95
src/models/Organization.ts
Normal file
95
src/models/Organization.ts
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
import mongoose, { Schema } from 'mongoose'
|
||||
import { Tag } from './Tag'
|
||||
|
||||
interface AllowedStringOptions {
|
||||
name: string;
|
||||
allowedValues: string[]
|
||||
}
|
||||
|
||||
class AllowedString extends mongoose.SchemaType {
|
||||
name: String
|
||||
allowedValues: string[] = []
|
||||
|
||||
constructor(key: string, options: AllowedStringOptions) {
|
||||
super(key, options)
|
||||
this.allowedValues = options.allowedValues
|
||||
this.name = options.name
|
||||
}
|
||||
|
||||
cast(value: any) {
|
||||
console.log(value + ' is being validated')
|
||||
if (this.allowedValues.indexOf(value) === -1) {
|
||||
let validationStr: string = 'AllowedString: ' + value + ' must be one of which: [' + this.allowedValues.join(', ') + ']'
|
||||
console.log(validationStr)
|
||||
throw new Error(validationStr)
|
||||
}
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
mongoose.Schema.Types['AllowedString'] = AllowedString
|
||||
|
||||
const ScheduleIntervalBoundary = new Schema({
|
||||
hour: { type: Number },
|
||||
minute: { type: Number }
|
||||
})
|
||||
|
||||
const Media = new Schema({
|
||||
location: { type: String, required: true },
|
||||
bucket: { type: String },
|
||||
key: { type: String },
|
||||
type: {
|
||||
type: AllowedString,
|
||||
name: 'MediaType',
|
||||
allowedValues: ['cover', 'thumbnail', 'video', 'image']
|
||||
}
|
||||
})
|
||||
|
||||
const OrganizationVersion = new Schema({
|
||||
name: { type: String, required: true },
|
||||
descriptionShort: { type: String, required: true },
|
||||
descriptionLong: { type: String, required: true },
|
||||
thumbnail: { type: Media, required: true },
|
||||
gallery: [{ type: Media }],
|
||||
cover: { type: Media },
|
||||
contacts: [{
|
||||
name: { type: String, required: true },
|
||||
type: { type: String, required: true }, // (facebook,twitter,instagram,website,address,person,email,phone)
|
||||
content: { type: String, required: true },
|
||||
}],
|
||||
schedule: [{
|
||||
name: { type: String, required: true },
|
||||
description: { type: String },
|
||||
day: { type: String }, // (Mon,Tue,Wed,Thu,Fri,Sat,Sun)
|
||||
from: { type: ScheduleIntervalBoundary, required: true },
|
||||
to: { type: ScheduleIntervalBoundary, required: true }
|
||||
}],
|
||||
pricing: [{
|
||||
name: { type: String, required: true },
|
||||
priceLabel: { type: String, required: true },
|
||||
description: { type: String }
|
||||
}],
|
||||
tag: { type: Tag }
|
||||
})
|
||||
|
||||
const Organization = new Schema({
|
||||
admin_name: { type: String, required: true },
|
||||
email: { type: String, required: true },
|
||||
token: { type: String, required: true },
|
||||
validationState: {
|
||||
type: AllowedString,
|
||||
required: true,
|
||||
default: 'none',
|
||||
name: 'ValidationState',
|
||||
allowedValues: ['none', 'pending', 'rejected', 'published']
|
||||
},
|
||||
rejectionDescription: { type: String },
|
||||
proposedVersion: { type: OrganizationVersion },
|
||||
publishedVersion: { type: OrganizationVersion },
|
||||
createdAt: { type: Date },
|
||||
updatedAt: { type: Date },
|
||||
publishedAt: { type: Date },
|
||||
})
|
||||
|
||||
export default mongoose.model('Organization', Organization)
|
||||
11
src/models/Tag.ts
Normal file
11
src/models/Tag.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import mongoose, { Schema } from 'mongoose'
|
||||
|
||||
const _Tag = new Schema({
|
||||
name: { type: String, required: true },
|
||||
icon: { type: String, required: true },
|
||||
description: { type: String }
|
||||
})
|
||||
|
||||
export const Tag = _Tag
|
||||
|
||||
export default mongoose.model('Tag', _Tag)
|
||||
Loading…
Add table
Add a link
Reference in a new issue