Game create and edit form. Formatting (2 spaces)

This commit is contained in:
2024-06-11 14:33:28 +04:00
parent b7e137d798
commit 1374c2bd70
24 changed files with 795 additions and 564 deletions

View File

@@ -13,4 +13,16 @@ export abstract class FilesService {
false
);
}
public static async UploadTorrent(torrent: File) {
const formData = new FormData();
formData.append("torrent", torrent);
return await HTTPService.post(
`/files/torrent`,
coverNameSchema,
formData,
{},
false
);
}
}

View File

@@ -1,16 +1,25 @@
import { HTTPService } from "@/shared/utils/http";
import { gameCardsSchema, GameCardType } from "./schemas/gameCard";
import { gameCardsSchema } from "./schemas/gameCard";
import { GameCreateType, gameSchema } from "./schemas/game";
import { z } from "zod";
export abstract class GameService {
public static async getGameCards() {
return await HTTPService.get("/games/cards", gameCardsSchema);
}
public static async getGame(id: number) {
return await HTTPService.get(`/games/${id}`, gameSchema);
}
public static async changeGame(id: number, gameInfo: GameCreateType) {
return await HTTPService.put(`/games/${id}`, gameSchema, gameInfo);
}
public static async GetGameCards() {
return await HTTPService.get("/games/cards", gameCardsSchema);
}
public static async GetGame(id: number) {
return await HTTPService.get(`/games/${id}`, gameSchema);
}
public static async ChangeGame(id: number, gameInfo: GameCreateType) {
return await HTTPService.put(`/games/${id}`, gameSchema, gameInfo);
}
public static async AddGame(gameInfo: GameCreateType) {
return await HTTPService.post(`/games`, gameSchema, gameInfo);
}
public static GetEmptyGame(): GameCreateType {
return {
title: "",
torrent_file: "",
};
}
}

View File

@@ -3,9 +3,9 @@ import { GameType, GameCreateType, gameCreateSchema } from "./schemas/game";
import { GameService } from "./game";
export {
GameService,
gameCreateSchema,
type GameType,
type GameCreateType,
type GameCardType,
GameService,
gameCreateSchema,
type GameType,
type GameCreateType,
type GameCardType,
};

View File

@@ -3,23 +3,30 @@ import { gameCardBaseSchema } from "./gameCard";
export const gameBaseSchema = gameCardBaseSchema.merge(
z.object({
torrent_file: z.string().min(1),
torrent_file: z.string().min(3, "У раздачи должен быть .torrent файл"),
trailer: z.string().optional(),
system: z.string().optional(),
processor: z.string().optional(),
memory: z.string().optional(),
graphics: z.string().optional(),
storage: z.string().optional(),
system: z.string().optional().nullable(),
processor: z.string().optional().nullable(),
memory: z.string().optional().nullable(),
graphics: z.string().optional().nullable(),
storage: z.string().optional().nullable(),
developer: z.string().optional(),
language: z.string().optional(),
download_size: z.string().optional(),
developer: z.string().optional().nullable(),
language: z.string().optional().nullable(),
download_size: z.string().optional().nullable(),
release_date: z
.string()
.min(1)
.transform((d) => new Date(d)),
.optional()
.nullable()
.transform((d) =>
d
? new Date(d).toLocaleDateString("en-us", {
year: "numeric",
})
: undefined
),
})
);

View File

@@ -1,10 +1,10 @@
import { z } from "zod";
export const gameCardBaseSchema = z.object({
title: z.string().min(3),
cover: z.string().optional(),
description: z.string().optional(),
version: z.string().optional(),
title: z.string().min(3, "Слишком короткое название"),
cover: z.string().optional().nullable(),
description: z.string().optional().nullable(),
version: z.string().optional().nullable(),
});
export const gameCardSchema = gameCardBaseSchema.merge(

View File

@@ -1,16 +1,16 @@
import {
loginFormSchema,
loginFormFieldNames,
LoginForm,
loginFormSchema,
loginFormFieldNames,
LoginForm,
} from "./schemas/auth";
import { userSchema, User } from "./schemas/user";
import { UserService } from "./user";
export {
loginFormSchema,
loginFormFieldNames,
UserService,
userSchema,
type User,
type LoginForm,
loginFormSchema,
loginFormFieldNames,
UserService,
userSchema,
type User,
type LoginForm,
};

View File

@@ -2,29 +2,29 @@ import { z } from "zod";
import { userSchema } from "./user";
export const loginFormSchema = z.object({
username: z.string().min(3, "Логин слишком короткий"),
password: z.string().min(3, "Пароль слишком короткий"),
username: z.string().min(3, "Логин слишком короткий"),
password: z.string().min(3, "Пароль слишком короткий"),
});
export const loginFormFieldNames = {
username: "Логин",
password: "Пароль",
username: "Логин",
password: "Пароль",
};
export type LoginForm = z.infer<typeof loginFormSchema>;
export const tokenResponseSchema = z
.object({
access_token: z.string(),
token_type: z.string(),
})
.transform((tokenResponse) => tokenResponse.access_token);
.object({
access_token: z.string(),
token_type: z.string(),
})
.transform((tokenResponse) => tokenResponse.access_token);
export type TokenResponse = z.infer<typeof tokenResponseSchema>;
export const tokenDataSchema = userSchema.merge(
z.object({
expire: z
.string()
.min(1)
.transform((d) => new Date(d)),
})
z.object({
expire: z
.string()
.min(1)
.transform((d) => new Date(d)),
})
);
export type TokenData = z.infer<typeof tokenDataSchema>;