Pass logger to db

parent c9a29a8b
"use strict";
const logger = require('../libs/log');
const s2s = require('string-to-stream');
module.exports.getModelFunctions = model => {
module.exports.getModelFunctions = (model, logger) => {
let functions = {};
......@@ -60,7 +59,8 @@ module.exports.getModelFunctions = model => {
let fileInfo = await model.findOne({_id: id});
if(!fileInfo) {
logger.warn(`File ${id} not found in GridFs Model: ${model.modelName}`)
if(logger)
logger.warn(`File ${id} not found in GridFs Model: ${model.modelName}`)
return Buffer.from('File not exists!');
}
......@@ -87,7 +87,8 @@ module.exports.getModelFunctions = model => {
let info = await model.findOne({_id: id});
if(!info) {
logger.warn(`File ${id} not found in GridFs Model: ${model.modelName}`)
if(logger)
logger.warn(`File ${id} not found in GridFs Model: ${model.modelName}`)
return;
}
......
......@@ -7,7 +7,7 @@ const files = require('./files');
module.exports.connection = null;
module.exports.connect = async (uri, options) => {
module.exports.connect = async (uri, options, logger) => {
options = options || {};
mongoose.set('useNewUrlParser', true);
......@@ -35,7 +35,7 @@ module.exports.connect = async (uri, options) => {
connection: mongoose.connection
});
module.exports.filesFS = files.getModelFunctions(filesFS);
module.exports.filesFS = files.getModelFunctions(filesFS, logger);
let testingFS = gridFS.createModel({
bucketName: 'testing',
......@@ -43,7 +43,7 @@ module.exports.connect = async (uri, options) => {
connection: mongoose.connection
});
module.exports.testingFS = files.getModelFunctions(testingFS);
module.exports.testingFS = files.getModelFunctions(testingFS, logger);
let solutionFS = gridFS.createModel({
bucketName: 'solution',
......@@ -51,7 +51,7 @@ module.exports.connect = async (uri, options) => {
connection: mongoose.connection
});
module.exports.solutionFS = files.getModelFunctions(solutionFS);
module.exports.solutionFS = files.getModelFunctions(solutionFS, logger);
module.exports.defines = require('./defines')
module.exports.attachments = require('./attachment');
......
......@@ -2,8 +2,6 @@
const mongoose = require('mongoose');
const defines = require('./defines');
const TimetableSchema = new mongoose.Schema({
course: {
type: mongoose.Schema.Types.ObjectId,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment