82 lines
2.0 KiB
JavaScript
82 lines
2.0 KiB
JavaScript
// models/odoo/employee.js
|
|
import axios from "axios";
|
|
import { authenticate, JSON_RPC_URL, odooConfig } from "./index.js";
|
|
|
|
export const fetchEmployees = async () => {
|
|
const uid = await authenticate();
|
|
|
|
const payload = {
|
|
jsonrpc: "2.0",
|
|
method: "call",
|
|
params: {
|
|
service: "object",
|
|
method: "execute_kw",
|
|
args: [
|
|
odooConfig.db,
|
|
uid,
|
|
odooConfig.apiKey,
|
|
"hr.employee",
|
|
"search_read",
|
|
[],
|
|
{ fields: ["id", "name", "work_email"], limit: 10 },
|
|
],
|
|
},
|
|
id: 2,
|
|
};
|
|
|
|
const { data } = await axios.post(JSON_RPC_URL, payload);
|
|
return data.result;
|
|
};
|
|
|
|
export const checkEmployeeExists = async (employee_id) => {
|
|
const uid = await authenticate();
|
|
|
|
const payload = {
|
|
jsonrpc: "2.0",
|
|
method: "call",
|
|
params: {
|
|
service: "object",
|
|
method: "execute_kw",
|
|
args: [
|
|
odooConfig.db,
|
|
uid,
|
|
odooConfig.apiKey,
|
|
"hr.employee",
|
|
"search",
|
|
[[["id", "=", employee_id]]],
|
|
0,
|
|
],
|
|
},
|
|
id: 10,
|
|
};
|
|
|
|
const res = await axios.post(JSON_RPC_URL, payload);
|
|
return res.data.result && res.data.result.length > 0;
|
|
};
|
|
|
|
export const fetchEmployeeById = async (employee_id) => {
|
|
const uid = await authenticate();
|
|
|
|
const payload = {
|
|
jsonrpc: "2.0",
|
|
method: "call",
|
|
params: {
|
|
service: "object",
|
|
method: "execute_kw",
|
|
args: [
|
|
odooConfig.db,
|
|
uid,
|
|
odooConfig.apiKey,
|
|
"hr.employee",
|
|
"search_read",
|
|
[[["id", "=", employee_id]]],
|
|
{ fields: ["id", "name", "work_email"], limit: 1 },
|
|
],
|
|
},
|
|
id: 3,
|
|
};
|
|
|
|
const { data } = await axios.post(JSON_RPC_URL, payload);
|
|
return data.result[0] || null;
|
|
};
|