29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
import { Injectable } from "@nestjs/common";
|
|
import { PrismaMariaDbService } from "prisma/mariadb/prisma-mariadb.service";
|
|
import { Result } from "src/common/errors/result-error.factory";
|
|
import { AccountMemo } from "src/customer-support/dtos/account.dto";
|
|
|
|
@Injectable()
|
|
export class AccountMemoService {
|
|
constructor(private readonly prismaMariaDb: PrismaMariaDbService) { }
|
|
|
|
findMemosByAccountId = async (accountId: number): Promise<Result<AccountMemo[], string>> => {
|
|
const listOfMemos: AccountMemo[] = [];
|
|
|
|
const rawListOfMemos = await this.prismaMariaDb.account_memo.findMany({
|
|
where: { id: accountId },
|
|
select: { last_updated: true, staff_id: true, memo: true },
|
|
});
|
|
if (!rawListOfMemos) return { success: false, error: 'MEMOS_NOT_FOUND' };
|
|
|
|
for (const memo of rawListOfMemos) {
|
|
listOfMemos.push({
|
|
last_updated: Number(memo.last_updated),
|
|
staff_id: Number(memo.staff_id),
|
|
memo: memo.memo ? memo.memo : '',
|
|
});
|
|
}
|
|
return { success: true, data: listOfMemos }
|
|
}
|
|
|
|
} |