update: remove the blog from the response of the update or create blog

This commit is contained in:
mahyargdz
2025-09-03 08:59:17 +03:30
parent 672fe9b783
commit 5e0bd3dce7
24 changed files with 526 additions and 385 deletions
@@ -1,6 +1,7 @@
import { BadRequestException, Injectable, Logger } from "@nestjs/common";
import { DataSource, Not } from "typeorm";
import { IUserIpAndHeaders } from "../../../common/decorators/user.decorator";
import { CommonMessage, UserMessage } from "../../../common/enums/message.enum";
import { UserType } from "../../access-logs/enums/user-type.enum";
import { AccessLogService } from "../../access-logs/providers/access-log.service";
@@ -37,7 +38,7 @@ export class CustomersService {
private readonly accessLogService: AccessLogService,
) {}
async createCustomer(createDto: CreateCustomerDto) {
async createCustomer(createDto: CreateCustomerDto, userIpAndHeaders: IUserIpAndHeaders) {
const queryRunner = this.dataSource.createQueryRunner();
try {
@@ -73,11 +74,14 @@ export class CustomersService {
await queryRunner.commitTransaction();
// Log the customer creation
await this.accessLogService.logCreate("User", user.id, createDto, {
userType: UserType.ADMIN,
await this.accessLogService.logCreate("User", UserType.ADMIN, {
user: { id: userIpAndHeaders.userId },
endpoint: "/customers",
requestId: userIpAndHeaders.headers["x-request-id"],
ipAddress: userIpAndHeaders.ip,
userAgent: userIpAndHeaders.headers["user-agent"],
actionDescription: `Admin created customer: ${createDto.email}`,
metadata: {
createdBy: "admin",
email: createDto.email,
phone: createDto.phone,
},
@@ -93,7 +97,7 @@ export class CustomersService {
}
}
//************************************************ */
async updateCustomer(customerId: string, updateDto: UpdateCustomerDto) {
async updateCustomer(customerId: string, updateDto: UpdateCustomerDto, userIpAndHeaders: IUserIpAndHeaders) {
const queryRunner = this.dataSource.createQueryRunner();
try {
await queryRunner.connect();
@@ -241,6 +245,21 @@ export class CustomersService {
await queryRunner.commitTransaction();
await this.accessLogService.logUpdate("User", customerId, UserType.ADMIN, {
user: { id: userIpAndHeaders.userId },
endpoint: "/customers",
requestId: userIpAndHeaders.headers["x-request-id"],
ipAddress: userIpAndHeaders.ip,
userAgent: userIpAndHeaders.headers["user-agent"],
actionDescription: `Admin updated customer: ${customerId}`,
metadata: {
email: email,
phone: phone,
},
oldValues: JSON.stringify({ ...user }),
newValues: JSON.stringify({ ...updateDto }),
});
return {
message: CommonMessage.UPDATE_SUCCESS,
};