Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const productModel = (mongoose, slugify) => {
/**
* Product schema definition
* @type {Schema}
*/
const productSchema = new Schema({
// Product name
name: {type: String, required: true},
// Product slug (used in url)
slug: {type: String, required: true, unique: true},
// Product price
price: {type: Number},
// Product main image src
mainImage: {type: String},
// Product brand
brand: {type: Schema.Types.ObjectId, ref: 'Brand', required:true},
// Product category
category: {type: Schema.Types.ObjectId, ref: 'Category', required:true},
// Product creator
creator: {type: Schema.Types.ObjectId, ref: 'User', required:true},
});
/**
* Get brand
* @return {Brand}
*/
productSchema.method('getBrand', async function() {
await this.populate('brand').execPopulate();
return this.brand;
});
/**
"use strict";
let mongoose = require('mongoose'),
Schema = require('mongoose').Schema,
bcrypt = require('bcrypt-nodejs');
// define the schema for our user model
let userSchema = new Schema({
email: {type: String, required: true},
username: {type: String},
password: {type: String, required: true},
avatar: {type: String},
token: {type: String, required: true},
display_name: {type: String, required: true},
last_login_date: {type: Schema.Types.Date, default: Date.now},
rules: {type: Schema.Types.Mixed, default: {}},
settings: {
updated_at: {type: Schema.Types.Date, default: Date.now},
menu: {type: String}
},
status: {type: String, enum: ['Available', 'Block', 'Pending']},
created_date: {type: Schema.Types.Date, default: Date.now},
role_id: {type: Schema.Types.ObjectId, ref: 'Objects'},
type: {type: Schema.Types.Number, enum: [0, -1]},
activation_code: {type: String},
reset_password_token: {type: String},
reset_password_expires: {type: Schema.Types.Date},
logs: [{type: Schema.Types.Mixed}],
web_session: [{
session_id: {type: String},
ip_address: {type: String},
import mongoose, { Schema } from 'mongoose';
import timestamps from 'mongoose-timestamp';
import mongooseStringQuery from 'mongoose-string-query';
import autopopulate from 'mongoose-autopopulate';
export const ShareSchema = new Schema(
{
user: {
type: Schema.Types.ObjectId,
ref: 'User',
index: true,
required: true,
autopopulate: {
select: [
'name',
'email',
'username',
'bio',
'url',
'twitter',
'background',
'admin',
],
},
},
import mongoose, { Schema } from 'mongoose';
import timestamps from 'mongoose-timestamp';
import mongooseStringQuery from 'mongoose-string-query';
import autopopulate from 'mongoose-autopopulate';
import stream from 'getstream';
import config from '../config';
import RSS from './rss';
import Podcast from './podcast';
import { getStreamClient } from '../utils/stream';
export const FollowSchema = new Schema(
{
user: {
type: Schema.Types.ObjectId,
ref: 'User',
required: true,
autopopulate: {
select: [
'name',
'email',
'username',
'bio',
'url',
'twitter',
'background',
'admin',
],
},
index: true,
},
import mongoose, { Schema } from 'mongoose'
/*
* Define the project schema as two parts.
* First is the participants
* Second is the details of the project
* This will allow us to expand the complexity of either without collision of names or too much confusion from 1d objects
*/
const userType = {
type : Schema.Types.ObjectId,
ref: 'User'
}
const messageBoard = new Schema({
text: {
type: String
}
},
{timestamps: true})
const project = {
owner: userType,
members: [userType],
applicants: [userType],
messages: [messageBoard],
title: { type: String },
import { Schema, model } from 'mongoose';
const MessageSchema = new Schema({
createTime: { type: Date, default: Date.now, index: true },
from: {
type: Schema.Types.ObjectId,
ref: 'User',
},
to: {
type: String,
index: true,
},
type: {
type: String,
enum: ['text', 'image', 'code', 'invite', 'system'],
default: 'text',
},
content: {
type: String,
default: '',
},
});