mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-21 13:55:45 +00:00
128 lines
3.2 KiB
TypeScript
128 lines
3.2 KiB
TypeScript
import { BaseApiService } from '@/services/api/base';
|
|
import { BaseApiResponse } from '@/types/api/api-general';
|
|
import {
|
|
Uniformity,
|
|
UniformityDetail,
|
|
VerifyUniformityPayload,
|
|
VerifyUniformityResponse,
|
|
CreateUniformityPayload,
|
|
} from '@/types/api/uniformity/uniformity';
|
|
|
|
export class UniformityApiService extends BaseApiService<
|
|
Uniformity,
|
|
CreateUniformityPayload,
|
|
VerifyUniformityPayload
|
|
> {
|
|
constructor(basePath: string) {
|
|
super(basePath);
|
|
}
|
|
|
|
async getUniformity(): Promise<BaseApiResponse<Uniformity> | undefined> {
|
|
return await this.customRequest<BaseApiResponse<Uniformity>>('');
|
|
}
|
|
|
|
async getUniformityDetail(
|
|
id: number
|
|
): Promise<BaseApiResponse<UniformityDetail> | undefined> {
|
|
return await this.customRequest<BaseApiResponse<UniformityDetail>>(
|
|
`/${id}`
|
|
);
|
|
}
|
|
|
|
async createUniformity(
|
|
payload: CreateUniformityPayload
|
|
): Promise<BaseApiResponse<Uniformity> | undefined> {
|
|
const formData = new FormData();
|
|
formData.append('date', payload.date);
|
|
formData.append('week', payload.week.toString());
|
|
formData.append(
|
|
'project_flock_kandang_id',
|
|
payload.project_flock_kandang_id.toString()
|
|
);
|
|
|
|
if (payload.file) {
|
|
formData.append('file', payload.file);
|
|
}
|
|
|
|
return await this.create(formData as unknown as CreateUniformityPayload);
|
|
}
|
|
|
|
async verifyUniformity(
|
|
payload: VerifyUniformityPayload
|
|
): Promise<BaseApiResponse<VerifyUniformityResponse> | undefined> {
|
|
const formData = new FormData();
|
|
formData.append('date', payload.date);
|
|
formData.append('week', payload.week.toString());
|
|
formData.append(
|
|
'project_flock_kandang_id',
|
|
payload.project_flock_kandang_id.toString()
|
|
);
|
|
|
|
if (payload.file) {
|
|
formData.append('file', payload.file);
|
|
}
|
|
|
|
return await this.customRequest<BaseApiResponse<VerifyUniformityResponse>>(
|
|
'/verify',
|
|
{
|
|
method: 'POST',
|
|
payload: formData as unknown as Record<string, unknown>,
|
|
}
|
|
);
|
|
}
|
|
|
|
async approve(
|
|
idOrIds: number | number[],
|
|
notes?: string
|
|
): Promise<BaseApiResponse<Uniformity[]> | undefined> {
|
|
const approvable_ids = Array.isArray(idOrIds) ? idOrIds : [idOrIds];
|
|
return await this.customRequest<BaseApiResponse<Uniformity[]>>(
|
|
'approvals',
|
|
{
|
|
method: 'POST',
|
|
payload: {
|
|
action: 'APPROVED',
|
|
approvable_ids,
|
|
notes,
|
|
},
|
|
}
|
|
);
|
|
}
|
|
|
|
async reject(
|
|
idOrIds: number | number[],
|
|
notes: string = ''
|
|
): Promise<BaseApiResponse<Uniformity[]> | undefined> {
|
|
const approvable_ids = Array.isArray(idOrIds) ? idOrIds : [idOrIds];
|
|
return await this.customRequest<BaseApiResponse<Uniformity[]>>(
|
|
'approvals',
|
|
{
|
|
method: 'POST',
|
|
payload: {
|
|
action: 'REJECTED',
|
|
approvable_ids,
|
|
notes,
|
|
},
|
|
}
|
|
);
|
|
}
|
|
|
|
async bulkDelete(
|
|
ids: number[]
|
|
): Promise<BaseApiResponse<Uniformity[]> | undefined> {
|
|
return await this.customRequest<BaseApiResponse<Uniformity[]>>(
|
|
'bulk-delete',
|
|
{
|
|
method: 'POST',
|
|
payload: {
|
|
ids,
|
|
},
|
|
}
|
|
);
|
|
}
|
|
}
|
|
|
|
export const UniformityApi = new UniformityApiService(
|
|
'http://localhost:4010/api/production/uniformities'
|
|
);
|