connect-the-dots / cloud-js / GetAllLevelStats.js
GetAllLevelStats.js
Raw
const { DataApi } = require("@unity-services/cloud-save-1.4");

module.exports = async ({ context }) => {
  const { projectId } = context;
  const cloudSave = new DataApi(context);
  const COLLECTION = "level-stats";
  const KEY = "level-completion";

  const resp = await cloudSave.getPrivateCustomItems(
    projectId,
    COLLECTION,
    [KEY]
  );

  const stats = (resp.data.results[0]?.value) ?? {};
  return { Data: stats };
};