import { BaseApiService } from '@/services/api/base'; import { BaseApiResponse } from '@/types/api/api-general'; import { Uniformity, UniformityDetail, VerifyUniformityPayload, VerifyUniformityResponse, CreateUniformityPayload, } from '@/types/api/production/uniformity'; export class UniformityApiService extends BaseApiService< Uniformity, CreateUniformityPayload, VerifyUniformityPayload > { constructor(basePath: string) { super(basePath); } async getUniformity( project_flock_kandang_id?: number, start_date?: string, end_date?: string, page?: number, limit?: number ): Promise | undefined> { return await this.customRequest>('', { method: 'GET', params: { project_flock_kandang_id: project_flock_kandang_id, start_date: start_date, end_date: end_date, page: page, limit: limit, }, }); } async getUniformityDetail( id: number, with_details = false ): Promise | undefined> { return await this.customRequest>( `/${id}`, { method: 'GET', params: { with_details: with_details, }, } ); } async createUniformity( payload: CreateUniformityPayload ): Promise | undefined> { const formData = new FormData(); formData.append('date', payload.date); formData.append( 'project_flock_kandang_id', payload.project_flock_kandang_id.toString() ); if (payload.document) { formData.append('document', payload.document); } return await this.customRequest>('', { method: 'POST', payload: formData as unknown as Record, }); } async verifyUniformity( payload: VerifyUniformityPayload ): Promise | undefined> { const formData = new FormData(); if (payload.document) { formData.append('document', payload.document); } return await this.customRequest>( '/verify', { method: 'POST', payload: formData as unknown as Record, } ); } async approve( idOrIds: number | number[], notes?: string ): Promise | undefined> { const approvable_ids = Array.isArray(idOrIds) ? idOrIds : [idOrIds]; return await this.customRequest>( 'approvals', { method: 'POST', payload: { action: 'APPROVED', approvable_ids, notes, }, } ); } async reject( idOrIds: number | number[], notes: string = '' ): Promise | undefined> { const approvable_ids = Array.isArray(idOrIds) ? idOrIds : [idOrIds]; return await this.customRequest>( 'approvals', { method: 'POST', payload: { action: 'REJECTED', approvable_ids, notes, }, } ); } async delete(id: number): Promise | undefined> { return await this.customRequest>(`/${id}`, { method: 'DELETE', }); } } export const UniformityApi = new UniformityApiService( 'production/uniformities' // 'http://localhost:4010/api/production/uniformities' );