Initial schema ideas for logging

This commit is contained in:
Tuan Dang
2022-12-17 15:10:30 -05:00
parent c12eeac9b3
commit 2e84b7e354
7 changed files with 106 additions and 4 deletions
+4 -1
View File
@@ -12,6 +12,7 @@ import Token, { IToken } from './token';
import User, { IUser } from './user';
import UserAction, { IUserAction } from './userAction';
import Workspace, { IWorkspace } from './workspace';
import Log, { ILog } from './log';
export {
BackupPrivateKey,
@@ -41,5 +42,7 @@ export {
UserAction,
IUserAction,
Workspace,
IWorkspace
IWorkspace,
Log,
ILog
};
+46
View File
@@ -0,0 +1,46 @@
import { Schema, model, Types } from 'mongoose';
export interface ILog {
_id: Types.ObjectId;
user: Types.ObjectId;
workspace: Types.ObjectId;
event: string;
source: string;
ipAddress: string;
}
// TODO: need a way to store payload info for each
// log
// which secret is being ref etc.
const logSchema = new Schema<ILog>(
{
user: {
type: Schema.Types.ObjectId,
ref: 'User'
},
workspace: {
type: Schema.Types.ObjectId,
ref: 'Workspace'
},
event: {
type: String,
required: true
},
source: { // should this just be a payload attr?
type: String,
required: true
},
ipAddress: { // store in bytes?
type: String,
required: true
}
}, {
timestamps: true
}
);
const Log = model<ILog>('Log', logSchema);
export default Log;