Setup fetch and wip fetchall route for getting companies.
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { connectWiseApi } from "../../constants";
|
||||
import { Company } from "../../types/ConnectWiseTypes";
|
||||
|
||||
export const fetchCwCompanyById = async (
|
||||
companyId: number,
|
||||
): Promise<Company | null> => {
|
||||
try {
|
||||
const response = await connectWiseApi.get(
|
||||
`/company/companies/${companyId}`,
|
||||
);
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
console.error(
|
||||
`Error fetching company with ID ${companyId}:`,
|
||||
(error as any).response?.data || error,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
import { Company } from "../../../generated/prisma/client";
|
||||
import { prisma } from "../../constants";
|
||||
import { fetchCwCompanyById } from "./fetchCompany";
|
||||
|
||||
export const updateCwInternalCompany = async (
|
||||
companyId: number,
|
||||
): Promise<Company | null> => {
|
||||
const cwCompany = await fetchCwCompanyById(companyId);
|
||||
if (!cwCompany) return null;
|
||||
|
||||
const updatedCompany = await prisma.company.upsert({
|
||||
where: { cw_CompanyId: cwCompany.id },
|
||||
create: {
|
||||
cw_CompanyId: cwCompany.id,
|
||||
cw_Identifier: cwCompany.identifier,
|
||||
name: cwCompany.name,
|
||||
},
|
||||
update: {
|
||||
name: cwCompany.name,
|
||||
},
|
||||
});
|
||||
|
||||
return updatedCompany;
|
||||
};
|
||||
Reference in New Issue
Block a user