-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Ability to track user activity navigation logs (#1167)
AB#105244 Co-authored-by: Tai Kamilla <taikamilla@gmail.com> Co-authored-by: unai-reliefapp <123092672+unai-reliefapp@users.noreply.github.com> Co-authored-by: MwanPygmay <59645813+MwanPygmay@users.noreply.github.com> Co-authored-by: Yafar Valverde <15035750+TaiKamilla@users.noreply.github.com>
- Loading branch information
1 parent
d10dfd7
commit 5233f6c
Showing
13 changed files
with
1,235 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { ReasonPhrases, StatusCodes } from 'http-status-codes'; | ||
|
||
/** Error interface */ | ||
export interface Error { | ||
status: number; | ||
fields: { | ||
name: { | ||
message: string; | ||
}; | ||
}; | ||
message: string; | ||
name: string; | ||
} | ||
|
||
/** Api Error class */ | ||
class ApiError extends Error implements Error { | ||
public status = 500; | ||
|
||
public success = false; | ||
|
||
public fields: { name: { message: string } } = { name: { message: '' } }; | ||
|
||
/** | ||
* Api Error class | ||
* | ||
* @param msg Message | ||
* @param statusCode Http status code number | ||
* @param name Error name | ||
*/ | ||
constructor( | ||
msg: string, | ||
statusCode: number, | ||
name: string = ReasonPhrases.INTERNAL_SERVER_ERROR | ||
) { | ||
super(); | ||
this.message = msg; | ||
this.status = statusCode; | ||
this.name = | ||
statusCode === StatusCodes.NOT_FOUND ? ReasonPhrases.NOT_FOUND : name; | ||
} | ||
} | ||
|
||
export default ApiError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Response } from 'express'; | ||
import { StatusCodes } from 'http-status-codes'; | ||
import { RouteDefinition } from '../types/route-definition'; | ||
|
||
/** | ||
* Provides services common to all API methods | ||
*/ | ||
export default abstract class BaseController { | ||
public abstract routes(): RouteDefinition[]; | ||
|
||
/** | ||
* Global method to send API response. | ||
* | ||
* @param res Express response | ||
* @param statusCode http status code | ||
*/ | ||
public send(res: Response, statusCode: number = StatusCodes.OK): void { | ||
let obj = {}; | ||
obj = res.locals.data; | ||
res.status(statusCode).send(obj); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { AccessibleRecordModel, accessibleRecordsPlugin } from '@casl/mongoose'; | ||
import mongoose, { Schema, Document } from 'mongoose'; | ||
|
||
/** Mongoose activity log schema declaration */ | ||
export interface ActivityLog extends Document { | ||
kind: 'ActivityLog'; | ||
userId: mongoose.Types.ObjectId; | ||
eventType: string; | ||
metadata: any; | ||
username: string; | ||
attributes: any; | ||
createdAt: Date; | ||
} | ||
|
||
/** Activity log documents interface declaration */ | ||
const schema = new Schema<ActivityLog>( | ||
{ | ||
userId: Schema.Types.ObjectId, | ||
eventType: String, | ||
username: String, | ||
metadata: Schema.Types.Mixed, | ||
attributes: Schema.Types.Mixed, | ||
}, | ||
{ | ||
timestamps: { createdAt: 'createdAt' }, | ||
} | ||
); | ||
|
||
schema.plugin(accessibleRecordsPlugin); | ||
|
||
/** Mongoose activity log model */ | ||
// eslint-disable-next-line @typescript-eslint/no-redeclare | ||
export const ActivityLog = mongoose.model< | ||
ActivityLog, | ||
AccessibleRecordModel<ActivityLog> | ||
>('ActivityLog', schema); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.