Adds the SchemaType 'UploadedFile' to mongoose in order to verify if file exists.
npm install @logicamente.info/mongoose-uploaded-filebash
$ npm i -S @logicamente.info/mongoose-uploaded-file # NPM users
$ yarn add @logicamente.info/mongoose-uploaded-file # YARN users
`
How to use
`JavaScript
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
// Add the UploadedFile SchemaType to mongoose
require('@logicamente.info/mongoose-uploaded-file').loadType(mongoose);
const UploadedFile = mongoose.Types.UploadedFile;
// If you haven't declared the const UploadedFile
// you can use 'mongoose.Types.UploadedFile'
const ProductSchema = Schema({
photo: { type: UploadedFile }
});
const Product = mongoose.model('Product', ProductSchema);
const p = new Product();
p.photo = '/upload/photo.jpg'
`
$3
It accepts all properties from mongoose String SchemaType.
`JavaScript
// This will transform the path into lowercase, then remove blank space
// at start and end, then validates if the file exists
var ProductSchema = Schema({
photo: { type: UploadedFile, required: true, lowercase: true, trim: true }
});
`
Testing
At root of this project, run npm test`