Setup fetch and wip fetchall route for getting companies.

This commit is contained in:
2026-01-26 18:14:28 -06:00
parent 7748e6171b
commit 24d0c066fd
6 changed files with 163 additions and 0 deletions
+19
View File
@@ -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;
}
};
+24
View File
@@ -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;
};