38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
import { fromPromise } from "xstate";
|
|
|
|
import type {
|
|
PrivateAlbumsResponse,
|
|
PrivateAlbumUnlockResponse,
|
|
} from "@/data/dto/private-room";
|
|
import { getPrivateRoomRepository } from "@/data/repositories/private_room_repository";
|
|
import { Result } from "@/utils";
|
|
|
|
import {
|
|
PRIVATE_ROOM_CHARACTER,
|
|
PRIVATE_ROOM_PAGE_SIZE,
|
|
} from "./private-room-machine.helpers";
|
|
|
|
export const loadPrivateAlbumsActor =
|
|
fromPromise<PrivateAlbumsResponse>(async () => {
|
|
const repo = getPrivateRoomRepository();
|
|
const result = await repo.getAlbums({
|
|
character: PRIVATE_ROOM_CHARACTER,
|
|
limit: PRIVATE_ROOM_PAGE_SIZE,
|
|
});
|
|
if (Result.isErr(result)) throw result.error;
|
|
return result.data;
|
|
});
|
|
|
|
export const unlockPrivateAlbumActor = fromPromise<
|
|
PrivateAlbumUnlockResponse,
|
|
{ albumId: string; expectedCost: number }
|
|
>(async ({ input }) => {
|
|
const repo = getPrivateRoomRepository();
|
|
const result = await repo.unlockAlbum(
|
|
input.albumId,
|
|
input.expectedCost,
|
|
);
|
|
if (Result.isErr(result)) throw result.error;
|
|
return result.data;
|
|
});
|