- Add BoardPost model (author, title, seeking/offering, note, tags) with validator requiring at least one of seeking/offering - Add BoardChannel model (name, slackChannelId, tagSlugs) - Add boardPost/boardChannel create+update Zod schemas - Trim Member.board subdoc to only slackHandle (drop topics, details, offerPeerSupport, availability, personalMessage) - Remove old boardUpdateSchema
28 lines
860 B
JavaScript
28 lines
860 B
JavaScript
import mongoose from 'mongoose'
|
|
|
|
const boardPostSchema = new mongoose.Schema({
|
|
author: {
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
ref: 'Member',
|
|
required: true,
|
|
},
|
|
title: { type: String, required: true, maxlength: 120 },
|
|
seeking: { type: String, maxlength: 500 },
|
|
offering: { type: String, maxlength: 500 },
|
|
note: { type: String, maxlength: 300 },
|
|
tags: [String],
|
|
}, { timestamps: true })
|
|
|
|
boardPostSchema.pre('validate', function (next) {
|
|
const seeking = (this.seeking || '').trim()
|
|
const offering = (this.offering || '').trim()
|
|
if (!seeking && !offering) {
|
|
this.invalidate('seeking', 'At least one of seeking or offering must be provided')
|
|
}
|
|
next()
|
|
})
|
|
|
|
boardPostSchema.index({ author: 1 })
|
|
boardPostSchema.index({ createdAt: -1 })
|
|
|
|
export default mongoose.models.BoardPost || mongoose.model('BoardPost', boardPostSchema)
|