Create Post.ts
This commit is contained in:
30
src/lib/scripts/Post.ts
Normal file
30
src/lib/scripts/Post.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import mongoose from "mongoose";
|
||||
|
||||
const reqString = {
|
||||
type: String,
|
||||
required: true,
|
||||
};
|
||||
|
||||
const postSchema = new mongoose.Schema({
|
||||
imageDes: reqString,
|
||||
timeStamp: Date,
|
||||
reactions: Array,
|
||||
});
|
||||
|
||||
export class Pickup {
|
||||
model: mongoose.Model<any>;
|
||||
upsert: any;
|
||||
constructor() {
|
||||
this.model = mongoose.model('post', postSchema);
|
||||
this.upsert = { upsert: true };
|
||||
}
|
||||
async create(imageDes: string, reactions: Array<any>) {
|
||||
const newEntry = new this.model({
|
||||
imageDes: imageDes,
|
||||
timeStamp: new Date().toISOString(),
|
||||
reactions: reactions,
|
||||
});
|
||||
await newEntry.save();
|
||||
return newEntry;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user