task-d.5.6
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { z } from 'zod';
|
||||
import {
|
||||
opportunityMarkLostSchema
|
||||
} from '@/features/crm/opportunities/schemas/opportunity.schema';
|
||||
import { getOpportunityDetail, markOpportunityAsLost } from '@/features/crm/opportunities/server/service';
|
||||
import { opportunityMarkLostSchema } from '@/features/crm/opportunities/schemas/lifecycle.schema';
|
||||
import { markOpportunityLost } from '@/features/crm/opportunities/server/lifecycle.service';
|
||||
import { getOpportunityDetail } from '@/features/crm/opportunities/server/service';
|
||||
import { PERMISSIONS } from '@/lib/auth/rbac';
|
||||
import { AuthError, requireOrganizationAccess } from '@/lib/auth/session';
|
||||
|
||||
@@ -17,6 +16,7 @@ export async function POST(request: NextRequest, { params }: Params) {
|
||||
const { organization, session, membership } = await requireOrganizationAccess({
|
||||
permission: PERMISSIONS.crmOpportunityMarkLost
|
||||
});
|
||||
|
||||
const payload = opportunityMarkLostSchema.parse(await request.json());
|
||||
const accessContext = {
|
||||
organizationId: organization.id,
|
||||
@@ -30,8 +30,9 @@ export async function POST(request: NextRequest, { params }: Params) {
|
||||
branchScopeMode: membership.branchScopeMode === 'assigned' ? 'assigned' : 'all',
|
||||
productScopeMode: membership.productScopeMode === 'assigned' ? 'assigned' : 'all'
|
||||
};
|
||||
|
||||
const before = await getOpportunityDetail(id, organization.id, accessContext);
|
||||
const updated = await markOpportunityAsLost(id, organization.id, session.user.id, payload, accessContext);
|
||||
const updated = await markOpportunityLost(id, organization.id, session.user.id, payload, accessContext);
|
||||
const after = await getOpportunityDetail(id, organization.id, accessContext);
|
||||
|
||||
return NextResponse.json({
|
||||
@@ -60,4 +61,3 @@ export async function POST(request: NextRequest, { params }: Params) {
|
||||
return NextResponse.json({ message: 'Unable to mark opportunity as lost' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user