list of card to card
This commit is contained in:
@@ -27,6 +27,8 @@ import { SalonSubscriptionsService } from '../subscriptions/salon-subscriptions.
|
||||
import { UploaderService } from '../uploader/uploader.service';
|
||||
import { UserRole } from '../users/enums/user-role.enum';
|
||||
import { ShortLinksService } from '../short-links/short-links.service';
|
||||
import { DepositListItemDto } from './dto/deposit-list-item.dto';
|
||||
import { FindDepositsQueryDto } from './dto/find-deposits-query.dto';
|
||||
import { PublicDepositPaymentDto } from './dto/public-deposit-payment.dto';
|
||||
import { ReviewDepositDto } from './dto/review-deposit.dto';
|
||||
import { Payment } from './entities/payment.entity';
|
||||
@@ -253,6 +255,43 @@ export class CardToCardDepositService {
|
||||
return this.getPublicPaymentByToken(token);
|
||||
}
|
||||
|
||||
async findForSalon(
|
||||
user: AuthUser,
|
||||
query: FindDepositsQueryDto,
|
||||
): Promise<DepositListItemDto[]> {
|
||||
if (user.role !== UserRole.SALON && user.role !== UserRole.ADMIN) {
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
|
||||
const qb = this.paymentsRepository
|
||||
.createQueryBuilder('payment')
|
||||
.innerJoinAndSelect('payment.reserve', 'reserve')
|
||||
.innerJoinAndSelect('reserve.salon', 'salon')
|
||||
.leftJoinAndSelect('reserve.customer', 'customer')
|
||||
.leftJoinAndSelect('customer.user', 'customerUser')
|
||||
.where('payment.type = :type', { type: PaymentType.DEPOSIT })
|
||||
.andWhere('payment.method = :method', {
|
||||
method: PaymentMethod.CARD_TO_CARD,
|
||||
})
|
||||
.orderBy('payment.createdAt', 'DESC');
|
||||
|
||||
if (query.status) {
|
||||
qb.andWhere('payment.status = :status', { status: query.status });
|
||||
}
|
||||
|
||||
if (!this.authorizationService.isAdmin(user)) {
|
||||
qb.andWhere('salon.ownerId = :ownerId', { ownerId: user.id });
|
||||
}
|
||||
|
||||
const limit = query.limit ?? 50;
|
||||
const offset = query.offset ?? 0;
|
||||
qb.take(limit).skip(offset);
|
||||
|
||||
const payments = await qb.getMany();
|
||||
|
||||
return payments.map((payment) => this.toDepositListItem(payment));
|
||||
}
|
||||
|
||||
async findForReview(paymentId: string, user: AuthUser): Promise<Payment> {
|
||||
const payment = await this.loadPaymentWithRelations(paymentId);
|
||||
this.assertCanReview(user, payment);
|
||||
@@ -391,4 +430,23 @@ export class CardToCardDepositService {
|
||||
private rialToToman(amountRial: number): number {
|
||||
return Math.round(amountRial / 10);
|
||||
}
|
||||
|
||||
private toDepositListItem(payment: Payment): DepositListItemDto {
|
||||
const user = payment.reserve?.customer?.user;
|
||||
const customerName = user
|
||||
? `${user.firstName} ${user.lastName}`.trim()
|
||||
: 'مشتری';
|
||||
|
||||
return {
|
||||
id: payment.id,
|
||||
status: payment.status,
|
||||
amountToman: this.rialToToman(payment.amountRial),
|
||||
receiptUrl: payment.receiptUrl,
|
||||
createdAt: payment.createdAt,
|
||||
customerName,
|
||||
customerMobile: user?.mobile ?? null,
|
||||
appointmentDate: payment.reserve?.appointmentDate ?? null,
|
||||
startTime: payment.reserve?.startTime ?? null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user