json.tsx 1010 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { compressToBase64 } from "lz-string";
  2. import { altogic } from "src/api/altogic";
  3. type JSON = {
  4. _id: string;
  5. createdAt: Date;
  6. updatedAt: Date;
  7. name: string;
  8. private: boolean;
  9. json: string;
  10. };
  11. const saveJson = async ({ id, data }): Promise<{ data: { _id: string } }> => {
  12. const compressedData = compressToBase64(data);
  13. if (id) {
  14. return await altogic.endpoint.put(`json/${id}`, {
  15. json: compressedData,
  16. });
  17. }
  18. return await altogic.endpoint.post("json", {
  19. json: compressedData,
  20. });
  21. };
  22. const getAllJson = async (): Promise<{ data: JSON[] }> =>
  23. await altogic.endpoint.get(`json`);
  24. const getJson = async (id: string): Promise<{ data: JSON }> =>
  25. await altogic.endpoint.get(`json/${id}`);
  26. const updateJson = async (id: string, data: object) =>
  27. await altogic.endpoint.put(`json/${id}`, {
  28. ...data,
  29. });
  30. const deleteJson = async (id: string) => await altogic.endpoint.delete(`json/${id}`);
  31. export { saveJson, getJson, getAllJson, updateJson, deleteJson };