251223:1649 On going update to 1.7.0: Refoctory drawing Module & document number Module
Some checks failed
Spec Validation / validate-markdown (push) Has been cancelled
Spec Validation / validate-diagrams (push) Has been cancelled
Spec Validation / check-todos (push) Has been cancelled

This commit is contained in:
admin
2025-12-23 16:49:16 +07:00
parent 0d6432ab83
commit 7db6a003db
81 changed files with 4703 additions and 1449 deletions

View File

@@ -114,21 +114,25 @@ describe('use-correspondence hooks', () => {
const mockResponse = { id: 1, title: 'New Correspondence' };
vi.mocked(correspondenceService.create).mockResolvedValue(mockResponse);
const { wrapper, queryClient } = createTestQueryClient();
const { wrapper } = createTestQueryClient();
const { result } = renderHook(() => useCreateCorrespondence(), { wrapper });
await act(async () => {
await result.current.mutateAsync({
title: 'New Correspondence',
subject: 'New Correspondence',
projectId: 1,
correspondenceTypeId: 1,
typeId: 1,
originatorId: 1,
recipients: []
});
});
expect(correspondenceService.create).toHaveBeenCalledWith({
title: 'New Correspondence',
subject: 'New Correspondence',
projectId: 1,
correspondenceTypeId: 1,
typeId: 1,
originatorId: 1,
recipients: []
});
expect(toast.success).toHaveBeenCalledWith('Correspondence created successfully');
});
@@ -146,9 +150,11 @@ describe('use-correspondence hooks', () => {
await act(async () => {
try {
await result.current.mutateAsync({
title: '',
subject: '',
projectId: 1,
correspondenceTypeId: 1,
typeId: 1,
originatorId: 1,
recipients: []
});
} catch {
// Expected to throw
@@ -163,7 +169,7 @@ describe('use-correspondence hooks', () => {
describe('useUpdateCorrespondence', () => {
it('should update correspondence and invalidate cache', async () => {
const mockResponse = { id: 1, title: 'Updated Correspondence' };
const mockResponse = { id: 1, subject: 'Updated Correspondence' };
vi.mocked(correspondenceService.update).mockResolvedValue(mockResponse);
const { wrapper } = createTestQueryClient();
@@ -172,12 +178,12 @@ describe('use-correspondence hooks', () => {
await act(async () => {
await result.current.mutateAsync({
id: 1,
data: { title: 'Updated Correspondence' },
data: { subject: 'Updated Correspondence' },
});
});
expect(correspondenceService.update).toHaveBeenCalledWith(1, {
title: 'Updated Correspondence',
subject: 'Updated Correspondence',
});
expect(toast.success).toHaveBeenCalledWith('Correspondence updated successfully');
});
@@ -210,11 +216,11 @@ describe('use-correspondence hooks', () => {
await act(async () => {
await result.current.mutateAsync({
id: 1,
data: { recipientIds: [2, 3] },
data: { note: 'Ready for review' },
});
});
expect(correspondenceService.submit).toHaveBeenCalledWith(1, { recipientIds: [2, 3] });
expect(correspondenceService.submit).toHaveBeenCalledWith(1, { note: 'Ready for review' });
expect(toast.success).toHaveBeenCalledWith('Correspondence submitted successfully');
});
});
@@ -230,13 +236,13 @@ describe('use-correspondence hooks', () => {
await act(async () => {
await result.current.mutateAsync({
id: 1,
data: { action: 'approve', comment: 'LGTM' },
data: { action: 'APPROVE', comments: 'LGTM' },
});
});
expect(correspondenceService.processWorkflow).toHaveBeenCalledWith(1, {
action: 'approve',
comment: 'LGTM',
action: 'APPROVE',
comments: 'LGTM',
});
expect(toast.success).toHaveBeenCalledWith('Action completed successfully');
});
@@ -255,7 +261,7 @@ describe('use-correspondence hooks', () => {
try {
await result.current.mutateAsync({
id: 1,
data: { action: 'approve' },
data: { action: 'APPROVE' },
});
} catch {
// Expected to throw

View File

@@ -110,6 +110,8 @@ describe('use-rfa hooks', () => {
await result.current.mutateAsync({
projectId: 1,
subject: 'Test RFA',
rfaTypeId: 1,
toOrganizationId: 1
});
});
@@ -132,6 +134,8 @@ describe('use-rfa hooks', () => {
await result.current.mutateAsync({
projectId: 1,
subject: '',
rfaTypeId: 1,
toOrganizationId: 1
});
} catch {
// Expected
@@ -175,13 +179,13 @@ describe('use-rfa hooks', () => {
await act(async () => {
await result.current.mutateAsync({
id: 1,
data: { action: 'approve', comment: 'Approved' },
data: { action: 'APPROVE', comments: 'Approved' },
});
});
expect(rfaService.processWorkflow).toHaveBeenCalledWith(1, {
action: 'approve',
comment: 'Approved',
action: 'APPROVE',
comments: 'Approved',
});
expect(toast.success).toHaveBeenCalledWith('Workflow status updated successfully');
});
@@ -200,7 +204,7 @@ describe('use-rfa hooks', () => {
try {
await result.current.mutateAsync({
id: 1,
data: { action: 'reject' },
data: { action: 'REJECT' },
});
} catch {
// Expected

View File

@@ -1,13 +1,15 @@
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { contractDrawingService } from '@/lib/services/contract-drawing.service';
import { shopDrawingService } from '@/lib/services/shop-drawing.service';
import { asBuiltDrawingService } from '@/lib/services/asbuilt-drawing.service'; // Added
import { SearchContractDrawingDto, CreateContractDrawingDto } from '@/types/dto/drawing/contract-drawing.dto';
import { SearchShopDrawingDto, CreateShopDrawingDto } from '@/types/dto/drawing/shop-drawing.dto';
import { SearchAsBuiltDrawingDto, CreateAsBuiltDrawingDto } from '@/types/dto/drawing/asbuilt-drawing.dto'; // Added
import { toast } from 'sonner';
type DrawingType = 'CONTRACT' | 'SHOP';
type DrawingSearchParams = SearchContractDrawingDto | SearchShopDrawingDto;
type CreateDrawingData = CreateContractDrawingDto | CreateShopDrawingDto;
type DrawingType = 'CONTRACT' | 'SHOP' | 'AS_BUILT'; // Added AS_BUILT
type DrawingSearchParams = SearchContractDrawingDto | SearchShopDrawingDto | SearchAsBuiltDrawingDto;
type CreateDrawingData = CreateContractDrawingDto | CreateShopDrawingDto | CreateAsBuiltDrawingDto;
export const drawingKeys = {
all: ['drawings'] as const,
@@ -25,8 +27,10 @@ export function useDrawings(type: DrawingType, params: DrawingSearchParams) {
queryFn: async () => {
if (type === 'CONTRACT') {
return contractDrawingService.getAll(params as SearchContractDrawingDto);
} else {
} else if (type === 'SHOP') {
return shopDrawingService.getAll(params as SearchShopDrawingDto);
} else {
return asBuiltDrawingService.getAll(params as SearchAsBuiltDrawingDto);
}
},
placeholderData: (previousData) => previousData,
@@ -39,8 +43,10 @@ export function useDrawing(type: DrawingType, id: number | string) {
queryFn: async () => {
if (type === 'CONTRACT') {
return contractDrawingService.getById(id);
} else {
} else if (type === 'SHOP') {
return shopDrawingService.getById(id);
} else {
return asBuiltDrawingService.getById(id);
}
},
enabled: !!id,
@@ -56,8 +62,10 @@ export function useCreateDrawing(type: DrawingType) {
mutationFn: async (data: CreateDrawingData) => {
if (type === 'CONTRACT') {
return contractDrawingService.create(data as CreateContractDrawingDto);
} else {
} else if (type === 'SHOP') {
return shopDrawingService.create(data as CreateShopDrawingDto);
} else {
return asBuiltDrawingService.create(data as CreateAsBuiltDrawingDto);
}
},
onSuccess: () => {

View File

@@ -105,3 +105,28 @@ export function useCorrespondenceTypes() {
queryFn: () => masterDataService.getCorrespondenceTypes(),
});
}
// --- Drawing Categories Hooks ---
export function useContractDrawingCategories() {
return useQuery({
queryKey: ['contract-drawing-categories'],
queryFn: () => masterDataService.getContractDrawingCategories(),
});
}
export function useShopMainCategories(projectId: number) {
return useQuery({
queryKey: ['shop-main-categories', projectId],
queryFn: () => masterDataService.getShopMainCategories(projectId),
enabled: !!projectId,
});
}
export function useShopSubCategories(projectId: number, mainCategoryId?: number) {
return useQuery({
queryKey: ['shop-sub-categories', projectId, mainCategoryId],
queryFn: () => masterDataService.getShopSubCategories(projectId, mainCategoryId),
enabled: !!projectId,
});
}