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
52 changes: 42 additions & 10 deletions server/service/admin-club.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { FindOptionsWhere, In, IsNull, Repository } from 'typeorm'
import { InjectRepository, Service } from '../provider'
import { ClubEntity, ClubHistoryEntity, ServiceUserEntity, UserEntity } from '../infra/database/entities'
import {
ClubEntity,
ClubHistoryEntity,
ServiceUserEntity,
UserEntity,
} from '../infra/database/entities'
import { ClubManagerEntity } from '../infra/database/entities/club-manager.entity'
import { ClubManagerRegisterRequestEntity } from '../infra/database/entities/club-manager-register-request.entity'
import { ClubVerificationRequestEntity } from '../infra/database/entities/club-verification-request.entity'
Expand Down Expand Up @@ -53,6 +58,7 @@ export type AdminClubDetail = {
sns: string
introduction: string | null
created_at: string
reject_reason: string | null
}
manager_data: {
name: string
Expand Down Expand Up @@ -87,6 +93,7 @@ export type AdminClubManagerRequestItem = {
student_id: string
}
status: ClubStatus
reject_reason: string | null
created_at: string
}

Expand All @@ -96,6 +103,7 @@ export type AdminClubVerificationRequestItem = {
club_name: string
category: string
status: ClubStatus
reject_reason: string | null
created_at: string
}

Expand Down Expand Up @@ -126,7 +134,7 @@ export class AdminClubService {

const clubs = await this.clubRepository.find({
where,
order: { createdAt: 'ASC' },
order: { createdAt: 'DESC' },
})

if (clubs.length === 0) return []
Expand Down Expand Up @@ -193,6 +201,7 @@ export class AdminClubService {
sns: club.sns,
introduction: club.introduction,
created_at: club.createdAt,
reject_reason: club.rejectReason,
},
manager_data: {
name: manager?.name ?? '',
Expand Down Expand Up @@ -334,6 +343,7 @@ export class AdminClubService {
'manager_request.phone AS applicant_phone',
'manager_request.student_id AS applicant_student_id',
'manager_request.status AS status',
'manager_request.reject_reason AS reject_reason',
'manager_request.created_at AS created_at',
])
.orderBy('manager_request.created_at', 'DESC')
Expand All @@ -351,6 +361,7 @@ export class AdminClubService {
applicant_phone: string
applicant_student_id: string
status: ClubStatus
reject_reason: string | null
created_at: string
}>()

Expand All @@ -365,6 +376,7 @@ export class AdminClubService {
student_id: request.applicant_student_id,
},
status: request.status,
reject_reason: request.reject_reason,
created_at: request.created_at,
}))
}
Expand All @@ -381,6 +393,7 @@ export class AdminClubService {
"COALESCE(club.name, '') AS club_name",
"COALESCE(club.category, '') AS category",
'verification_request.status AS status',
'verification_request.reject_reason AS reject_reason',
'verification_request.created_at AS created_at',
])
.orderBy('verification_request.created_at', 'DESC')
Expand All @@ -395,6 +408,7 @@ export class AdminClubService {
club_name: string
category: string
status: ClubStatus
reject_reason: string | null
created_at: string
}>()

Expand All @@ -404,6 +418,7 @@ export class AdminClubService {
club_name: request.club_name,
category: request.category,
status: request.status,
reject_reason: request.reject_reason,
created_at: request.created_at,
}))
}
Expand All @@ -426,15 +441,15 @@ export class AdminClubService {
throw new NotFoundError('manager request not found')
}

if (request.status !== PENDING_CLUB_STATUS) {
throw new ConflictError('manager request already processed')
}

const processedAt = new Date().toISOString()
const isApproved = decision.status === PUBLIC_CLUB_STATUS
const isRejected = decision.status === REJECTED_CLUB_STATUS
const isPending = decision.status === PENDING_CLUB_STATUS

if (isApproved) {
if (request.status !== PENDING_CLUB_STATUS) {
throw new ConflictError('can only approve from PENDING status')
}
const existingManager = await clubManagerRepository.findOneBy({ clubId: request.clubId })
if (existingManager) {
throw new ConflictError('club already has a manager')
Expand All @@ -449,6 +464,13 @@ export class AdminClubService {
})
}

if (isPending && request.status === PUBLIC_CLUB_STATUS) {
await clubManagerRepository.delete({
clubId: request.clubId,
serviceUserId: request.serviceUserId,
})
}

await managerRequestRepository.update(
{ id: request.id },
{
Expand Down Expand Up @@ -485,15 +507,15 @@ export class AdminClubService {
throw new NotFoundError('verification request not found')
}

if (request.status !== PENDING_CLUB_STATUS) {
throw new ConflictError('verification request already processed')
}

const processedAt = new Date().toISOString()
const isApproved = decision.status === PUBLIC_CLUB_STATUS
const isRejected = decision.status === REJECTED_CLUB_STATUS
const isPending = decision.status === PENDING_CLUB_STATUS

if (isApproved) {
if (request.status !== PENDING_CLUB_STATUS) {
throw new ConflictError('can only approve from PENDING status')
}
await clubRepository.update(
{ uuid: request.clubId },
{
Expand All @@ -503,6 +525,16 @@ export class AdminClubService {
)
}

if (isPending && request.status === PUBLIC_CLUB_STATUS) {
await clubRepository.update(
{ uuid: request.clubId },
{
isOfficialVerified: false,
verifiedAt: null,
},
)
}

await verificationRequestRepository.update(
{ id: request.id },
{
Expand Down
8 changes: 4 additions & 4 deletions src/admin/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
AdminClubHistoriesResponse,
} from 'src/lib/schemas/admin'
import { ADMIN_AUTH_TOKEN_KEY, buildQuery } from 'src/admin/constants'
import type { DecisionStatus, StatusFilter } from 'src/admin/types'
import type { ClubStatus, StatusFilter } from 'src/admin/types'

type FetchOptions = NonNullable<Parameters<typeof fetch>[1]>

Expand Down Expand Up @@ -59,7 +59,7 @@ export const fetchHistories = (query: string) =>

export const updateClubStatus = (payload: {
uuid: string
status: DecisionStatus
status: ClubStatus
reject_reason?: string
is_official_verified: boolean
}) =>
Expand All @@ -74,7 +74,7 @@ export const updateClubStatus = (payload: {

export const updateManagerRequestStatus = (payload: {
id: number
status: DecisionStatus
status: ClubStatus
reject_reason?: string
}) =>
request(`/api/v2/admin/clubs/manager-requests/${payload.id}/status`, {
Expand All @@ -87,7 +87,7 @@ export const updateManagerRequestStatus = (payload: {

export const updateVerificationStatus = (payload: {
id: number
status: DecisionStatus
status: ClubStatus
reject_reason?: string
}) =>
request(`/api/v2/admin/clubs/verifications/${payload.id}/status`, {
Expand Down
Loading
Loading