For people who still have this problem or face it in the future, here is a solution:
afterDelete(event, ctx) {
const { result, params } = event;
ctx = strapi.requestContext.get(); // info about request to delete a row in Article
const deletedBy = ctx.state.user; // user who executed the delete operation
strapi.entityService.create("api::auditlog.auditlog", {
data: {
contentType: "Article",
action: "Delete Content",
content: result,
author: result.createdBy,
method: ctx.request.method,
params: params,
request: event,
editedBy: deletedBy,
},
});
},
In the previous procedure we took the data of the user who executed the deletion point. The log will show the user’s complete information once the Article record is deleted and the log is generated. You will be able to see information that may be sensitive for your purposes such as the password (most likely you have it encrypted), however if you do not want to show this information you could do something like the following, within the same function AfterDelete() or you can create a new one that is called inside afterDelete():
afterDelete(event, ctx) {
const { result, params } = event;
ctx = strapi.requestContext.get(); // info about request to delete a row in Article
const user = ctx.state.user; // user who executed the delete operation
const { id, username, email, isActive, createdAt, updatedAt } = userInfo
const deletedBy = {
id,
username,
email,
isActive,
createdAt,
updatedAt,
};
strapi.entityService.create("api::auditlog.auditlog", {
data: {
contentType: "Article",
action: "Delete Content",
content: result,
author: result.createdBy,
method: ctx.request.method,
params: params,
request: event,
editedBy: deletedBy,
},
});
},
Remember that you can create a separate function that is responsible for transforming your user to make cleaner code and shorter and more readable functions.