Initial commit: NestJS NextJS pnpm monorepo
This commit is contained in:
commit
610dcf202b
175 files changed
+25172
No files matched your search
@@ -0,0 +1,74 @@
|
||||
'use server'
|
||||
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { Manufacturer, ManufacturerCreate } from "@/apps/frontend/types/catalog";
|
||||
import { sites } from '../_config/sites';
|
||||
|
||||
export async function manufacturerCreate(data: ManufacturerCreate): Promise<ActionResult> {
|
||||
|
||||
const result = await fetch('http://192.168.50.205/api/manufacturer', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
|
||||
const resultData = await result.json();
|
||||
|
||||
if (!result.ok) {
|
||||
return {
|
||||
success: false,
|
||||
errors: resultData.message,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// revalidatePath(sites.manufacturer.new.url);
|
||||
return { success: true, data:resultData };
|
||||
|
||||
|
||||
}
|
||||
|
||||
export async function manufacturerUpdate(id: string, data: Partial<ManufacturerCreate>): Promise<ActionResult> {
|
||||
console.log(data, id);
|
||||
const result = await fetch(`http://192.168.50.205/api/manufacturer/${id}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data),
|
||||
})
|
||||
|
||||
|
||||
const resultData = await result.json();
|
||||
|
||||
if (!result.ok) {
|
||||
return {
|
||||
success: false,
|
||||
errors: resultData.message,
|
||||
};
|
||||
}
|
||||
|
||||
revalidatePath(sites.manufacturer.update.url + '/' + id);
|
||||
revalidatePath(sites.manufacturer.url );
|
||||
return { success: true, data:resultData.data };
|
||||
}
|
||||
|
||||
export async function manufacturerFindAll(): Promise<Manufacturer[]> {
|
||||
|
||||
const result = await fetch(`http://192.168.50.205/api/manufacturer`, {
|
||||
method: 'GET',
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
})
|
||||
const data = await result.json();
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function manufacturerFindById(id: string): Promise<Manufacturer> {
|
||||
|
||||
const result = await fetch(`http://192.168.50.205/api/manufacturer/${id}`, {
|
||||
method: 'GET',
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
})
|
||||
const data = await result.json();
|
||||
|
||||
return data;
|
||||
}
|
||||
Reference in new issue
Block a user