All files / src/lib/api/pro projects.ts

84.61% Statements 11/13
83.33% Branches 5/6
87.5% Functions 7/8
84.61% Lines 11/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75        102x           2x 2x       2x     2x       1x           1x             1x             1x           1x                 1x                                  
// Pro API - Project Operations
import { request } from "../base";
import type { Project } from "./types";
 
export const projectsApi = {
	async list(
		proId: string,
		params?: Record<string, string>,
		options?: { includePhotoCount?: boolean },
	) {
		const merged: Record<string, string> = { ...(params ?? {}) };
		Iif (options?.includePhotoCount) {
			merged.includePhotoCount = "1";
		}
		const query =
			Object.keys(merged).length > 0
				? `?${new URLSearchParams(merged).toString()}`
				: "";
		return request<Project[]>(`/api/pro/${proId}/projects${query}`);
	},
 
	async get(proId: string, projectId: string) {
		return request<Project & { photos: unknown[] }>(
			`/api/pro/${proId}/projects/${projectId}`,
		);
	},
 
	async create(proId: string, data: Partial<Project>) {
		return request<Project>(`/api/pro/${proId}/projects`, {
			method: "POST",
			body: data,
		});
	},
 
	async update(proId: string, projectId: string, data: Partial<Project>) {
		return request<Project>(`/api/pro/${proId}/projects/${projectId}`, {
			method: "PUT",
			body: data,
		});
	},
 
	async delete(proId: string, projectId: string) {
		return request(`/api/pro/${proId}/projects/${projectId}`, {
			method: "DELETE",
		});
	},
 
	async publish(proId: string, projectId: string) {
		return request<Project>(
			`/api/pro/${proId}/projects/${projectId}/publish`,
			{
				method: "POST",
			},
		);
	},
 
	async archive(proId: string, projectId: string) {
		return request<Project>(
			`/api/pro/${proId}/projects/${projectId}/archive`,
			{
				method: "POST",
			},
		);
	},
 
	async unarchive(proId: string, projectId: string) {
		return request<Project>(
			`/api/pro/${proId}/projects/${projectId}/unarchive`,
			{
				method: "POST",
			},
		);
	},
};