dsg
INSERT INTO `cp_filejs` (`id`,`app`,`path`,`modul`,`file_name`,`content`) VALUES ('283','2','u6/driver','','js/api/garage.js--','import {\r\n getSessionUser\r\n} from \\\\\\\\\\\\\\\'./auth.js\\\\\\\\\\\\\\\'\r\nimport {\r\n API_URL,\r\n TIMEOUT_MS_HIGH,\r\n TIMEOUT_MS_HIGHER,\r\n} from \\\\\\\\\\\\\\\'./consts.js\\\\\\\\\\\\\\\'\r\n\r\nexport const getUserGarage = async (profileId) => {\r\n try {\r\n const response = await fetch(`${API_URL}/wp-json/app/v1/get-user-garage`, {\r\n method: \\\\\\\"POST\\\\\\\",\r\n headers: {\r\n \\\\\\\"Content-Type\\\\\\\": \\\\\\\"application/json\\\\\\\",\r\n },\r\n body: JSON.stringify({\r\n user_id: profileId\r\n }),\r\n })\r\n\r\n const data = await response.json()\r\n if (response.status !== 200) {\r\n return []\r\n }\r\n\r\n return data\r\n } catch (error) {\r\n return []\r\n }\r\n}\r\n\r\nexport const getGargeById = async (garageId) => {\r\n try {\r\n const response = await fetch(`${API_URL}/wp-json/app/v1/get-garage`, {\r\n method: \\\\\\\"POST\\\\\\\",\r\n cache: \\\\\\\"force-cache\\\\\\\",\r\n headers: {\r\n \\\\\\\"Content-Type\\\\\\\": \\\\\\\"application/json\\\\\\\",\r\n },\r\n body: JSON.stringify({\r\n garage_id: garageId\r\n }),\r\n })\r\n\r\n const data = await response.json()\r\n\r\n if (response.status !== 200) {\r\n throw new Error(\\\\\\\\\\\\\\\'Failed to fetch users posts\\\\\\\\\\\\\\\')\r\n }\r\n\r\n return data\r\n } catch (error) {\r\n console.error(error)\r\n return null\r\n }\r\n}\r\n\r\nexport const getPostsForGarage = async (garageId, page = 1, tagged = false) => {\r\n try {\r\n const response = await fetch(`${API_URL}/wp-json/app/v1/get-garage-posts`, {\r\n method: \\\\\\\"POST\\\\\\\",\r\n headers: {\r\n \\\\\\\"Content-Type\\\\\\\": \\\\\\\"application/json\\\\\\\",\r\n },\r\n body: JSON.stringify({\r\n garage_id: garageId,\r\n page,\r\n limit: 10,\r\n tagged\r\n }),\r\n })\r\n\r\n const data = await response.json()\r\n if (response.status !== 200) {\r\n return null\r\n }\r\n\r\n return data\r\n } catch (error) {\r\n return null\r\n }\r\n}\r\n\r\nexport const addVehicleToGarage = async (data) => {\r\n const controller = new AbortController()\r\n const signal = controller.signal\r\n\r\n try {\r\n const user = await getSessionUser()\r\n if (!user) return\r\n\r\n setTimeout(() => {\r\n controller.abort()\r\n }, TIMEOUT_MS_HIGH)\r\n\r\n const response = await fetch(`${API_URL}/wp-json/app/v1/add-vehicle-to-garage`, {\r\n method: \\\\\\\"POST\\\\\\\",\r\n headers: {\r\n \\\\\\\"Content-Type\\\\\\\": \\\\\\\"application/json\\\\\\\",\r\n },\r\n body: JSON.stringify({\r\n ...data,\r\n user_id: user.id,\r\n }),\r\n signal\r\n })\r\n\r\n const res = await response.json()\r\n return res\r\n } catch (error) {\r\n if (error.name === \\\\\\\\\\\\\\\'AbortError\\\\\\\\\\\\\\\') {\r\n throw {\r\n message: \\\\\\\"Failed to add your vehicle, your connection timed out\\\\\\\",\r\n name: \\\\\\\"TimeOutError\\\\\\\"\r\n };\r\n } else {\r\n throw error; // Rethrow any other errors\r\n }\r\n }\r\n}\r\n\r\nexport const updateVehicleInGarage = async (data, garageId) => {\r\n const controller = new AbortController()\r\n const signal = controller.signal\r\n\r\n try {\r\n const user = await getSessionUser()\r\n if (!user) return\r\n\r\n setTimeout(() => {\r\n controller.abort()\r\n }, TIMEOUT_MS_HIGH)\r\n\r\n const response = await fetch(`${API_URL}/wp-json/app/v1/update-garage`, {\r\n method: \\\\\\\"POST\\\\\\\",\r\n headers: {\r\n \\\\\\\"Content-Type\\\\\\\": \\\\\\\"application/json\\\\\\\",\r\n },\r\n body: JSON.stringify({\r\n ...data,\r\n user_id: user.id,\r\n garage_id: garageId,\r\n }),\r\n signal\r\n })\r\n\r\n const res = await response.json()\r\n return res\r\n } catch (error) {\r\n if (error.name === \\\\\\\\\\\\\\\'AbortError\\\\\\\\\\\\\\\') {\r\n throw {\r\n message: \\\\\\\"Failed to update your vehicle, your connection timed out\\\\\\\",\r\n name: \\\\\\\"TimeOutError\\\\\\\"\r\n };\r\n } else {\r\n throw error; // Rethrow any other errors\r\n }\r\n }\r\n}\r\n\r\nexport const deleteVehicleFromGarage = async (garageId) => {\r\n const controller = new AbortController()\r\n const signal = controller.signal\r\n\r\n try {\r\n const user = await getSessionUser()\r\n if (!user) return\r\n\r\n setTimeout(() => {\r\n controller.abort()\r\n }, TIMEOUT_MS_HIGH)\r\n\r\n const response = await fetch(`${API_URL}/wp-json/app/v1/delete-garage`, {\r\n method: \\\\\\\"POST\\\\\\\",\r\n headers: {\r\n \\\\\\\"Content-Type\\\\\\\": \\\\\\\"application/json\\\\\\\",\r\n },\r\n body: JSON.stringify({\r\n user_id: user.id,\r\n garage_id: garageId,\r\n }),\r\n signal\r\n })\r\n\r\n const res = await response.json()\r\n return res\r\n } catch (error) {\r\n if (error.name === \\\\\\\\\\\\\\\'AbortError\\\\\\\\\\\\\\\') {\r\n throw {\r\n message: \\\\\\\"Failed to delete your vehicle, your connection timed out\\\\\\\",\r\n name: \\\\\\\"TimeOutError\\\\\\\"\r\n };\r\n } else {\r\n throw error; // Rethrow any other errors\r\n }\r\n }\r\n}');
Copy This

Warning: file_get_contents(/home/u340524018/domains/agniaga.com/public_html/sub/u6/driver/js/api/garage.js--): Failed to open stream: No such file or directory in /home/u340524018/domains/agniaga.com/public_html/sub/u2/cp/inc.filejs.php on line 190
import {
    getSessionUser
} from \\\\\\\'./auth.js\\\\\\\'
import {
    API_URL,
    TIMEOUT_MS_HIGH,
    TIMEOUT_MS_HIGHER,
} from \\\\\\\'./consts.js\\\\\\\'

export const getUserGarage = async (profileId) => {
    try {
        const response = await fetch(`${API_URL}/wp-json/app/v1/get-user-garage`, {
            method: \\\"POST\\\",
            headers: {
                \\\"Content-Type\\\": \\\"application/json\\\",
            },
            body: JSON.stringify({
                user_id: profileId
            }),
        })

        const data = await response.json()
        if (response.status !== 200) {
            return []
        }

        return data
    } catch (error) {
        return []
    }
}

export const getGargeById = async (garageId) => {
    try {
        const response = await fetch(`${API_URL}/wp-json/app/v1/get-garage`, {
            method: \\\"POST\\\",
            cache: \\\"force-cache\\\",
            headers: {
                \\\"Content-Type\\\": \\\"application/json\\\",
            },
            body: JSON.stringify({
                garage_id: garageId
            }),
        })

        const data = await response.json()

        if (response.status !== 200) {
            throw new Error(\\\\\\\'Failed to fetch users posts\\\\\\\')
        }

        return data
    } catch (error) {
        console.error(error)
        return null
    }
}

export const getPostsForGarage = async (garageId, page = 1, tagged = false) => {
    try {
        const response = await fetch(`${API_URL}/wp-json/app/v1/get-garage-posts`, {
            method: \\\"POST\\\",
            headers: {
                \\\"Content-Type\\\": \\\"application/json\\\",
            },
            body: JSON.stringify({
                garage_id: garageId,
                page,
                limit: 10,
                tagged
            }),
        })

        const data = await response.json()
        if (response.status !== 200) {
            return null
        }

        return data
    } catch (error) {
        return null
    }
}

export const addVehicleToGarage = async (data) => {
    const controller = new AbortController()
    const signal = controller.signal

    try {
        const user = await getSessionUser()
        if (!user) return

        setTimeout(() => {
            controller.abort()
        }, TIMEOUT_MS_HIGH)

        const response = await fetch(`${API_URL}/wp-json/app/v1/add-vehicle-to-garage`, {
            method: \\\"POST\\\",
            headers: {
                \\\"Content-Type\\\": \\\"application/json\\\",
            },
            body: JSON.stringify({
                ...data,
                user_id: user.id,
            }),
            signal
        })

        const res = await response.json()
        return res
    } catch (error) {
        if (error.name === \\\\\\\'AbortError\\\\\\\') {
            throw {
                message: \\\"Failed to add your vehicle, your connection timed out\\\",
                name: \\\"TimeOutError\\\"
            };
        } else {
            throw error; // Rethrow any other errors
        }
    }
}

export const updateVehicleInGarage = async (data, garageId) => {
    const controller = new AbortController()
    const signal = controller.signal

    try {
        const user = await getSessionUser()
        if (!user) return

        setTimeout(() => {
            controller.abort()
        }, TIMEOUT_MS_HIGH)

        const response = await fetch(`${API_URL}/wp-json/app/v1/update-garage`, {
            method: \\\"POST\\\",
            headers: {
                \\\"Content-Type\\\": \\\"application/json\\\",
            },
            body: JSON.stringify({
                ...data,
                user_id: user.id,
                garage_id: garageId,
            }),
            signal
        })

        const res = await response.json()
        return res
    } catch (error) {
        if (error.name === \\\\\\\'AbortError\\\\\\\') {
            throw {
                message: \\\"Failed to update your vehicle, your connection timed out\\\",
                name: \\\"TimeOutError\\\"
            };
        } else {
            throw error; // Rethrow any other errors
        }
    }
}

export const deleteVehicleFromGarage = async (garageId) => {
    const controller = new AbortController()
    const signal = controller.signal

    try {
        const user = await getSessionUser()
        if (!user) return

        setTimeout(() => {
            controller.abort()
        }, TIMEOUT_MS_HIGH)

        const response = await fetch(`${API_URL}/wp-json/app/v1/delete-garage`, {
            method: \\\"POST\\\",
            headers: {
                \\\"Content-Type\\\": \\\"application/json\\\",
            },
            body: JSON.stringify({
                user_id: user.id,
                garage_id: garageId,
            }),
            signal
        })

        const res = await response.json()
        return res
    } catch (error) {
        if (error.name === \\\\\\\'AbortError\\\\\\\') {
            throw {
                message: \\\"Failed to delete your vehicle, your connection timed out\\\",
                name: \\\"TimeOutError\\\"
            };
        } else {
            throw error; // Rethrow any other errors
        }
    }
}
Add JS Function Name