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
+47
View File
@@ -0,0 +1,47 @@
import { Company } from "../../generated/prisma/client";
import { updateCwInternalCompany } from "../modules/cw-utils/updateCompany";
/**
* Company Controller
*
* This class is for creating a controller that can manage company data,
* synchronize with external systems, and provide methods for accessing
* and updating company information within our internal system.
*/
export class CompanyController {
public readonly id: string;
public name: string;
public readonly cw_Identifier: string;
public readonly cw_CompanyId: number;
constructor(companyData: Company) {
this.id = companyData.id;
this.name = companyData.name;
this.cw_Identifier = companyData.cw_Identifier;
this.cw_CompanyId = companyData.cw_CompanyId;
}
/**
* Refresh Internal Company Data from ConnectWise
*
* This method fetches the latest company data from ConnectWise and updates
* the internal company information accordingly.
*
* @returns {ThisType} - Updated Controller
*/
public async refreshFromCW() {
const data = await updateCwInternalCompany(this.cw_CompanyId);
this.name = data?.name || this.name;
return this;
}
public toJson() {
return {
id: this.id,
name: this.name,
cw_Identifier: this.cw_Identifier,
cw_CompanyId: this.cw_CompanyId,
};
}
}