Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/features/auth/repositories/account.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type {
AccountWithProfile,
IAccountRepository,
} from '@/features/auth/repositories/account.repository.interface';
import { PrismaService } from '@/prisma';
import { activeWhere, PrismaService } from '@/prisma';

/**
* Account / AccountIdentity / UserProfile Repository 구체 구현.
Expand All @@ -37,7 +37,7 @@ export class AccountRepository implements IAccountRepository {
provider_subject: providerSubject,
// soft-delete extension 은 top-level where 에만 deleted_at 을 주입한다.
// 상위 엔티티(account)까지 활성인지는 직접 명시해야 탈퇴 계정이 새어나오지 않는다.
account: { deleted_at: null },
account: activeWhere,
},
include: {
account: {
Expand Down
37 changes: 18 additions & 19 deletions src/features/order/repositories/order.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
type AccountType,
} from '@prisma/client';

import { PrismaService } from '@/prisma';
import { activeWhere, PrismaService } from '@/prisma';

export interface MyOrderRow {
id: bigint;
Expand Down Expand Up @@ -128,7 +128,7 @@ export class OrderRepository {
} | null;
} | null> {
return this.prisma.account.findFirst({
where: { id: accountId, deleted_at: null },
where: { id: accountId },
select: {
account_type: true,
user_profile: {
Expand Down Expand Up @@ -270,14 +270,14 @@ export class OrderRepository {
take: args.limit,
include: {
items: {
where: { deleted_at: null },
where: activeWhere,
orderBy: { id: 'asc' },
take: 1,
include: {
product: {
select: {
images: {
where: { deleted_at: null },
where: activeWhere,
orderBy: { sort_order: 'asc' },
take: 1,
select: { image_url: true },
Expand Down Expand Up @@ -310,7 +310,7 @@ export class OrderRepository {
take: args.limit,
include: {
items: {
where: { deleted_at: null },
where: activeWhere,
orderBy: { id: 'asc' },
take: 1,
include: {
Expand All @@ -320,7 +320,7 @@ export class OrderRepository {
product: {
select: {
images: {
where: { deleted_at: null },
where: activeWhere,
orderBy: { sort_order: 'asc' },
take: 1,
select: { image_url: true },
Expand All @@ -330,7 +330,7 @@ export class OrderRepository {
},
},
_count: {
select: { items: { where: { deleted_at: null } } },
select: { items: { where: activeWhere } },
},
},
});
Expand Down Expand Up @@ -365,7 +365,6 @@ export class OrderRepository {
const rows = await this.prisma.orderItem.findMany({
where: {
order_id: { in: args.orderIds },
deleted_at: null,
order: {
account_id: args.accountId,
status: OrderStatus.PICKED_UP,
Expand Down Expand Up @@ -393,13 +392,13 @@ export class OrderRepository {
limit: number;
}): Promise<{ items: ReviewableOrderItemRow[]; totalCount: number }> {
const where = {
deleted_at: null,
...activeWhere,
order: {
account_id: args.accountId,
status: OrderStatus.PICKED_UP,
// soft-delete extension은 nested relation filter에 deleted_at을 주입하지
// 않으므로 삭제된 주문의 아이템이 노출되지 않게 명시한다
deleted_at: null,
...activeWhere,
},
OR: [
{ review: { is: null } },
Expand All @@ -421,7 +420,7 @@ export class OrderRepository {
product: {
select: {
images: {
where: { deleted_at: null },
where: activeWhere,
orderBy: { sort_order: 'asc' },
take: 1,
select: { image_url: true },
Expand Down Expand Up @@ -452,11 +451,11 @@ export class OrderRepository {
},
include: {
status_histories: {
where: { deleted_at: null },
where: activeWhere,
orderBy: { changed_at: 'asc' },
},
items: {
where: { deleted_at: null },
where: activeWhere,
orderBy: { id: 'asc' },
include: {
store: {
Expand All @@ -473,35 +472,35 @@ export class OrderRepository {
business_hours_text: true,
website_url: true,
business_hours: {
where: { deleted_at: null },
where: activeWhere,
orderBy: { day_of_week: 'asc' },
},
},
},
product: {
select: {
images: {
where: { deleted_at: null },
where: activeWhere,
orderBy: { sort_order: 'asc' },
take: 1,
select: { image_url: true },
},
},
},
option_items: {
where: { deleted_at: null },
where: activeWhere,
orderBy: { id: 'asc' },
},
custom_texts: {
where: { deleted_at: null },
where: activeWhere,
orderBy: { sort_order: 'asc' },
},
free_edits: {
where: { deleted_at: null },
where: activeWhere,
orderBy: { sort_order: 'asc' },
include: {
attachments: {
where: { deleted_at: null },
where: activeWhere,
orderBy: { sort_order: 'asc' },
},
},
Expand Down
36 changes: 17 additions & 19 deletions src/features/product/repositories/product-review.repository.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@nestjs/common';
import { Prisma, type ReviewMediaType } from '@prisma/client';

import { PrismaService } from '@/prisma';
import { activeWhere, PrismaService, visibleWhere } from '@/prisma';

export interface ProductReviewMediaRow {
media_type: ReviewMediaType;
Expand Down Expand Up @@ -76,10 +76,10 @@ export class ProductReviewRepository {
/** 공개 리뷰 공통 가드: 리뷰·상품·매장 모두 활성. */
private publicReviewWhere(photoOnly: boolean): Prisma.ReviewWhereInput {
return {
deleted_at: null,
product: { is_active: true, deleted_at: null },
store: { is_active: true, deleted_at: null },
...(photoOnly ? { media: { some: { deleted_at: null } } } : {}),
...activeWhere,
product: visibleWhere,
store: visibleWhere,
...(photoOnly ? { media: { some: activeWhere } } : {}),
};
}

Expand Down Expand Up @@ -214,7 +214,7 @@ export class ProductReviewRepository {
> {
if (reviewIds.length === 0) return [];
return this.prisma.review.findMany({
where: { id: { in: reviewIds }, deleted_at: null },
where: { id: { in: reviewIds } },
select: {
id: true,
store_id: true,
Expand All @@ -227,15 +227,15 @@ export class ProductReviewRepository {
},
},
media: {
where: { deleted_at: null, media_type: 'IMAGE' },
where: { ...activeWhere, media_type: 'IMAGE' },
orderBy: { sort_order: 'asc' },
take: 1,
select: { media_url: true },
},
order_item: {
select: {
free_edits: {
where: { deleted_at: null },
where: activeWhere,
orderBy: { sort_order: 'asc' },
take: 1,
select: { crop_image_url: true },
Expand Down Expand Up @@ -265,7 +265,7 @@ export class ProductReviewRepository {
): Promise<ProductReviewRow[]> {
if (reviewIds.length === 0) return [];
return this.prisma.review.findMany({
where: { id: { in: reviewIds }, deleted_at: null },
where: { id: { in: reviewIds } },
select: {
id: true,
rating: true,
Expand All @@ -285,7 +285,7 @@ export class ProductReviewRepository {
},
},
media: {
where: { deleted_at: null },
where: activeWhere,
orderBy: { sort_order: 'asc' },
select: {
media_type: true,
Expand All @@ -297,7 +297,7 @@ export class ProductReviewRepository {
order_item: {
select: {
option_items: {
where: { deleted_at: null },
where: activeWhere,
orderBy: { id: 'asc' },
select: {
group_name_snapshot: true,
Expand Down Expand Up @@ -333,7 +333,7 @@ export class ProductReviewRepository {
},
},
media: {
where: { deleted_at: null },
where: activeWhere,
orderBy: { sort_order: 'asc' },
select: {
media_type: true,
Expand All @@ -345,7 +345,7 @@ export class ProductReviewRepository {
order_item: {
select: {
option_items: {
where: { deleted_at: null },
where: activeWhere,
orderBy: { id: 'asc' },
select: {
group_name_snapshot: true,
Expand All @@ -361,7 +361,7 @@ export class ProductReviewRepository {
regular_price: true,
sale_price: true,
images: {
where: { deleted_at: null },
where: activeWhere,
orderBy: { sort_order: 'asc' },
take: 1,
select: { image_url: true },
Expand Down Expand Up @@ -394,7 +394,7 @@ export class ProductReviewRepository {
if (reviewIds.length === 0) return new Map();
const rows = await this.prisma.reviewLike.groupBy({
by: ['review_id'],
where: { review_id: { in: reviewIds }, deleted_at: null },
where: { review_id: { in: reviewIds } },
_count: { _all: true },
});
return new Map(rows.map((r) => [r.review_id, r._count._all]));
Expand All @@ -410,7 +410,6 @@ export class ProductReviewRepository {
where: {
review_id: { in: args.reviewIds },
account_id: args.accountId,
deleted_at: null,
},
select: { review_id: true },
});
Expand All @@ -424,7 +423,7 @@ export class ProductReviewRepository {
if (reviewIds.length === 0) return new Map();
const rows = await this.prisma.reviewComment.groupBy({
by: ['review_id'],
where: { review_id: { in: reviewIds }, deleted_at: null },
where: { review_id: { in: reviewIds } },
_count: { _all: true },
});
return new Map(rows.map((r) => [r.review_id, r._count._all]));
Expand All @@ -439,7 +438,6 @@ export class ProductReviewRepository {
return this.prisma.reviewComment.findMany({
where: {
review_id: args.reviewId,
deleted_at: null,
...(args.cursor !== undefined ? { id: { gt: args.cursor } } : {}),
},
select: {
Expand Down Expand Up @@ -467,7 +465,7 @@ export class ProductReviewRepository {
/** 리뷰 활성 댓글 수. */
async countReviewComments(reviewId: bigint): Promise<number> {
return this.prisma.reviewComment.count({
where: { review_id: reviewId, deleted_at: null },
where: { review_id: reviewId },
});
}
}
Loading
Loading