0f48d7abda
Allow store contactPhone as landline, show pending package audit badge, and split live vs pending packages in HQ review. Co-authored-by: Cursor <cursoragent@cursor.com>
115 lines
3.7 KiB
TypeScript
115 lines
3.7 KiB
TypeScript
import { Body, Controller, Get, Param, Put, Query, UseGuards } from '@nestjs/common';
|
|
import { JwtAuthGuard, AuthUser } from '../../common/guards/jwt-auth.guard';
|
|
import { HqAuthGuard } from '../../common/guards/hq-auth.guard';
|
|
import { ShopStoreGuard } from '../../common/guards/shop-store.guard';
|
|
import { CurrentUser } from '../../common/decorators/current-user.decorator';
|
|
import { StorePackageService } from './store-package.service';
|
|
|
|
@Controller('partner/stores')
|
|
@UseGuards(JwtAuthGuard)
|
|
export class PartnerStorePackageController {
|
|
constructor(private readonly packages: StorePackageService) {}
|
|
|
|
@Get(':storeId/packages')
|
|
getPackages(@CurrentUser() user: AuthUser, @Param('storeId') storeId: string) {
|
|
return this.packages.getPartnerPackages(user.actorId, BigInt(storeId));
|
|
}
|
|
|
|
@Put(':storeId/packages')
|
|
submitPackages(
|
|
@CurrentUser() user: AuthUser,
|
|
@Param('storeId') storeId: string,
|
|
@Body() body: { packages: unknown },
|
|
) {
|
|
const normalized = this.packages.normalizePackages(body.packages);
|
|
return this.packages.submitPartnerChangeRequest(user.actorId, BigInt(storeId), normalized);
|
|
}
|
|
|
|
@Get(':storeId/package-change-requests')
|
|
listRequests(@CurrentUser() user: AuthUser, @Param('storeId') storeId: string) {
|
|
return this.packages.listPartnerChangeRequests(user.actorId, BigInt(storeId));
|
|
}
|
|
}
|
|
|
|
@Controller('shop/store')
|
|
@UseGuards(JwtAuthGuard, ShopStoreGuard)
|
|
export class ShopStorePackageController {
|
|
constructor(private readonly packages: StorePackageService) {}
|
|
|
|
@Get('packages')
|
|
getPackages(@CurrentUser() user: AuthUser) {
|
|
return this.packages.getShopPackages(user.actorId, user.storeId!);
|
|
}
|
|
|
|
@Put('packages')
|
|
submitPackages(@CurrentUser() user: AuthUser, @Body() body: { packages: unknown }) {
|
|
const normalized = this.packages.normalizePackages(body.packages);
|
|
return this.packages.submitShopChangeRequest(user.actorId, user.storeId!, normalized);
|
|
}
|
|
}
|
|
|
|
@Controller('admin/stores')
|
|
@UseGuards(HqAuthGuard)
|
|
export class AdminStorePackageController {
|
|
constructor(private readonly packages: StorePackageService) {}
|
|
|
|
@Get(':storeId/packages')
|
|
getPackages(@Param('storeId') storeId: string) {
|
|
return this.packages.adminGetPackages(BigInt(storeId));
|
|
}
|
|
|
|
@Put(':storeId/packages')
|
|
savePackages(@Param('storeId') storeId: string, @Body() body: { packages: unknown }) {
|
|
const normalized = this.packages.normalizePackages(body.packages);
|
|
return this.packages.adminDirectSave(BigInt(storeId), normalized);
|
|
}
|
|
}
|
|
|
|
@Controller('admin/store-package-audits')
|
|
@UseGuards(HqAuthGuard)
|
|
export class AdminStorePackageAuditController {
|
|
constructor(private readonly packages: StorePackageService) {}
|
|
|
|
@Get('summary')
|
|
summary() {
|
|
return this.packages.adminAuditSummary();
|
|
}
|
|
|
|
@Get()
|
|
list(
|
|
@Query('status') status?: string,
|
|
@Query('page') page?: string,
|
|
@Query('pageSize') pageSize?: string,
|
|
) {
|
|
return this.packages.adminListAudits({
|
|
status: status || undefined,
|
|
page: page ? Number(page) : undefined,
|
|
pageSize: pageSize ? Number(pageSize) : undefined,
|
|
});
|
|
}
|
|
|
|
@Get(':requestId')
|
|
detail(@Param('requestId') requestId: string) {
|
|
return this.packages.adminGetAuditDetail(BigInt(requestId));
|
|
}
|
|
|
|
@Put(':requestId/audit')
|
|
audit(
|
|
@CurrentUser() user: AuthUser,
|
|
@Param('requestId') requestId: string,
|
|
@Body() body: { action: 'APPROVE' | 'REJECT'; rejectReason?: string },
|
|
) {
|
|
return this.packages.adminAuditRequest(BigInt(requestId), user.actorId, body);
|
|
}
|
|
}
|
|
|
|
@Controller('stores')
|
|
export class PublicStorePackageController {
|
|
constructor(private readonly packages: StorePackageService) {}
|
|
|
|
@Get(':storeId/packages')
|
|
list(@Param('storeId') storeId: string) {
|
|
return this.packages.listLivePackages(BigInt(storeId));
|
|
}
|
|
}
|