{"size": 1117, "ext": "js", "max_stars_repo_path": "backend/models/log.model.js", "max_stars_repo_name": "ktatu/mielentilatutkimus-thl", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "backend/models/log.model.js", "max_issues_repo_name": "ktatu/mielentilatutkimus-thl", "max_issues_repo_issues_event_min_datetime": "2021-09-27T12:00:57.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-01T20:21:59.000Z", "max_forks_repo_path": "backend/models/log.model.js", "max_forks_repo_name": "ktatu/mielentilatutkimus-thl", "max_forks_repo_forks_event_min_datetime": "2021-09-06T09:29:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-17T11:26:07.000Z"}
{"max_stars_count": null, "max_issues_count": 78, "max_forks_count": 2, "avg_line_length": 31.0277777778, "max_line_length": 93, "alphanum_fraction": 0.6589077887}
const mongoose = require('mongoose')
const Schema = mongoose.Schema

const LogSchema = new Schema({
    action: { type: String, required: true },
    category: { type: String, required: true },

    //createdBy: { type: ObjectId, ref: 'Account', required: true },
    //kaksi alla olevaa korvattaisiin yllä olevalla jos olisi käytössä tietokanta käyttäjille
    createdBy: { type: String, required: true },
    createdByRole: { type: String, required: true},

    message: { type: String, required: true },
    diff: { type: Schema.Types.Mixed },
    formId: { 
        type: mongoose.Schema.Types.ObjectId,
        ref:'admissionForm' },
    attachmentId: { 
        type: mongoose.Schema.Types.ObjectId,
        ref:'attachmentForm' }
},{
    timestamps: { createdAt: 'createdAt', updatedAt: 'updatedAt' },
})

LogSchema.set('toJSON', {
    transform: (document, returnedObject) => {
        returnedObject.id = returnedObject._id.toString()
        delete returnedObject._id
        delete returnedObject.__v
    }
})


LogSchema.index({ action: 1, category: 1 })

module.exports = mongoose.model('Log', LogSchema)