2024-12-23 19:13:36 +00:00
|
|
|
import baseUrl from "@/baseUrl";
|
|
|
|
|
import { AddPostModel } from "@/models/add.post.model";
|
|
|
|
|
import { IAllVotes } from "@/models/allVotes.model";
|
|
|
|
|
import { BannerModel } from "@/models/banner.model";
|
|
|
|
|
import { CategoriesModel } from "@/models/categories.model";
|
|
|
|
|
import { ChannelsModel } from "@/models/channels.model";
|
|
|
|
|
import { HomeModel } from "@/models/home.model";
|
|
|
|
|
import { LiveDescriptionModel } from "@/models/liveDescription.model";
|
|
|
|
|
import { ILotteryResponse } from "@/models/lottery/lottery.model";
|
|
|
|
|
import { MarqueeModel } from "@/models/marquee.model";
|
|
|
|
|
import { NewsModel, NewsType } from "@/models/news.model";
|
|
|
|
|
import { NewsItemModel } from "@/models/newsItem.model";
|
|
|
|
|
import { PageItemModel } from "@/models/pageItem.model";
|
|
|
|
|
import { PlansModel } from "@/models/plans.model";
|
|
|
|
|
import { PropertiesModel } from "@/models/properties.model";
|
|
|
|
|
import { IQuizQuestionsHistory } from "@/models/quizQuestionHistory.model";
|
|
|
|
|
import { IQuizQuestions } from "@/models/quizQuestions.model";
|
|
|
|
|
import { IQuizQuestionsWinners } from "@/models/quizQuestionsWinners.model";
|
|
|
|
|
import { MessagesByTvAdmin } from "@/models/sms/messagesByTvAdmis.model";
|
|
|
|
|
import { IMyTvAdmins } from "@/models/sms/my.tv.admins.model";
|
|
|
|
|
import { VideoModel } from "@/models/video.model";
|
|
|
|
|
import { VideosModel } from "@/models/videos.model";
|
|
|
|
|
import { IVote } from "@/models/vote.model";
|
|
|
|
|
import routes from "@/routes";
|
2025-02-10 13:23:33 +00:00
|
|
|
import { revalidateTag } from "next/cache";
|
2025-02-08 09:02:21 +00:00
|
|
|
import { cookies } from "next/headers";
|
2024-08-19 12:44:56 +00:00
|
|
|
|
|
|
|
|
export class Queries {
|
|
|
|
|
public static async getNews(
|
|
|
|
|
page: number,
|
2024-12-23 19:13:36 +00:00
|
|
|
{ perPage = 8 }: { perPage?: number }
|
2024-08-19 12:44:56 +00:00
|
|
|
): Promise<NewsModel> {
|
|
|
|
|
return await fetch(
|
|
|
|
|
`${baseUrl.NEWS_SRC}${routes.news}?locale=tm&count=${perPage}&page=${page}`,
|
|
|
|
|
{
|
|
|
|
|
next: { revalidate: 3600 },
|
2024-12-23 19:13:36 +00:00
|
|
|
}
|
2024-08-19 12:44:56 +00:00
|
|
|
).then((res) => res.json().then((res) => res as NewsModel));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async getlastNews(): Promise<NewsModel> {
|
2024-10-23 11:26:25 +00:00
|
|
|
return await fetch(`${baseUrl.NEWS_SRC}${routes.news}?locale=tm&count=5`, {
|
2024-08-19 12:44:56 +00:00
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}).then((res) => res.json().then((res) => res as NewsModel));
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-23 11:26:25 +00:00
|
|
|
public static async getHomeBanner3(): Promise<NewsType> {
|
|
|
|
|
return await fetch(`https://turkmentv.gov.tm/v2/api/slider?type=small3`, {
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}).then((res) => res.json().then((res) => res as NewsType));
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-23 12:01:01 +00:00
|
|
|
public static async getHomeBannerSingle3(id: string): Promise<NewsType> {
|
2024-12-23 19:13:36 +00:00
|
|
|
return await fetch(
|
|
|
|
|
`https://turkmentv.gov.tm/v2/api/slider?type=small3/${id}`,
|
|
|
|
|
{
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}
|
|
|
|
|
).then((res) => res.json().then((res) => res as NewsType));
|
2024-10-23 12:01:01 +00:00
|
|
|
}
|
|
|
|
|
|
2024-08-19 12:44:56 +00:00
|
|
|
public static async getNewsItem(id: string): Promise<NewsItemModel> {
|
|
|
|
|
return await fetch(`${baseUrl.NEWS_SRC}${routes.newsItem(id)}?locale=tm`, {
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}).then((res) => res.json().then((res) => res as NewsItemModel));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async getCategories(): Promise<CategoriesModel> {
|
|
|
|
|
return await fetch(`${baseUrl.MATERIALS_SRC}${routes.categories}`, {
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}).then((res) => res.json().then((res) => res as CategoriesModel));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async getChannels(): Promise<ChannelsModel> {
|
|
|
|
|
return await fetch(`${baseUrl.MATERIALS_SRC}${routes.channels}`, {
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}).then((res) => res.json().then((res) => res as ChannelsModel));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async getVideos(search: string): Promise<VideosModel> {
|
|
|
|
|
return await fetch(`${baseUrl.MATERIALS_SRC}${routes.videos(search)}`, {
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}).then((res) => res.json().then((res) => res as VideosModel));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async getLastVideos(): Promise<VideosModel> {
|
|
|
|
|
return await fetch(`${baseUrl.MATERIALS_SRC}${routes.lastVideos}`, {
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}).then((res) => res.json().then((res) => res as VideosModel));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async getVideo(id: number): Promise<VideoModel> {
|
2024-12-23 19:13:36 +00:00
|
|
|
return await fetch(`${baseUrl.MATERIALS_SRC}${routes.video(id)}`).then(
|
|
|
|
|
(res) => res.json().then((res) => res as VideoModel)
|
2024-09-12 10:50:14 +00:00
|
|
|
);
|
2024-08-19 12:44:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async getPage(id: string): Promise<PageItemModel> {
|
|
|
|
|
return await fetch(`${baseUrl.MATERIALS_SRC}${routes.pageItem(id)}`, {
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}).then((res) => res.json().then((res) => res as PageItemModel));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async getHome(): Promise<HomeModel> {
|
|
|
|
|
return await fetch(`${baseUrl.MATERIALS_SRC}${routes.home}`, {
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}).then((res) => res.json().then((res) => res as HomeModel));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async getSmallSlider1(): Promise<HomeModel> {
|
|
|
|
|
return await fetch(`${baseUrl.MATERIALS_SRC}${routes.homeSmallSlider_1}`, {
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}).then((res) => res.json().then((res) => res as HomeModel));
|
|
|
|
|
}
|
|
|
|
|
public static async getSmallSlider2(): Promise<HomeModel> {
|
|
|
|
|
return await fetch(`${baseUrl.MATERIALS_SRC}${routes.homeSmallSlider_2}`, {
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}).then((res) => res.json().then((res) => res as HomeModel));
|
|
|
|
|
}
|
|
|
|
|
public static async getSmallSlider3(): Promise<HomeModel> {
|
|
|
|
|
return await fetch(`${baseUrl.MATERIALS_SRC}${routes.homeSmallSlider_1}`, {
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}).then((res) => res.json().then((res) => res as HomeModel));
|
|
|
|
|
}
|
|
|
|
|
public static async getSmallSlider4(): Promise<HomeModel> {
|
|
|
|
|
return await fetch(`${baseUrl.MATERIALS_SRC}${routes.homeSmallSlider_2}`, {
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}).then((res) => res.json().then((res) => res as HomeModel));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async getMarquee(): Promise<MarqueeModel> {
|
2024-12-23 19:13:36 +00:00
|
|
|
return await fetch(
|
|
|
|
|
`${baseUrl.MATERIALS_SRC}${routes.marquee}?on_morquee=1`,
|
|
|
|
|
{
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}
|
|
|
|
|
).then((res) => res.json().then((res) => res as MarqueeModel));
|
2024-08-19 12:44:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async getBanner(): Promise<BannerModel> {
|
|
|
|
|
return await fetch(`${baseUrl.MATERIALS_SRC}${routes.banner}`, {
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}).then((res) => res.json().then((res) => res as BannerModel));
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-23 19:13:36 +00:00
|
|
|
public static async getLiveDescription(
|
|
|
|
|
channel: number
|
|
|
|
|
): Promise<LiveDescriptionModel> {
|
|
|
|
|
return await fetch(
|
|
|
|
|
`${baseUrl.MATERIALS_SRC}${routes.channelItem(channel)}`,
|
|
|
|
|
{
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}
|
|
|
|
|
).then((res) => res.json().then((res) => res as LiveDescriptionModel));
|
2024-08-19 12:44:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async getProperties(): Promise<PropertiesModel> {
|
|
|
|
|
return await fetch(`${baseUrl.API_SRC}${routes.properties}`, {
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}).then((res) => res.json().then((res) => res as PropertiesModel));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async getPlans(property_id: number): Promise<PlansModel> {
|
2024-12-23 19:13:36 +00:00
|
|
|
return await fetch(
|
|
|
|
|
`${baseUrl.API_SRC}${routes.plans(String(property_id))}`,
|
|
|
|
|
{
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}
|
|
|
|
|
).then((res) => res.json().then((res) => res as PlansModel));
|
2024-08-19 12:44:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async postAdvert(data: AddPostModel): Promise<Response> {
|
|
|
|
|
return await fetch(`${baseUrl.API_SRC}${routes.addPost}`, {
|
2024-12-23 19:13:36 +00:00
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
|
cache: "no-cache",
|
2024-08-19 12:44:56 +00:00
|
|
|
body: JSON.stringify(data),
|
2024-12-23 19:13:36 +00:00
|
|
|
method: "POST",
|
2024-08-19 12:44:56 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Quiz fetching ===========================================================================
|
|
|
|
|
public static async getQuizQuestions(): Promise<IQuizQuestions> {
|
|
|
|
|
return await fetch(`${baseUrl.QUIZ_SRC}${routes.getQuizQuestions}`, {
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}).then((res) => res.json().then((res) => res as IQuizQuestions));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async getQuiz(quiz_id: string): Promise<IQuizQuestions> {
|
|
|
|
|
return await fetch(`${baseUrl.QUIZ_SRC}${routes.getQuiz(quiz_id)}`, {
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}).then((res) => res.json().then((res) => res as IQuizQuestions));
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-23 19:13:36 +00:00
|
|
|
public static async getQuizHistory(
|
|
|
|
|
id: number
|
|
|
|
|
): Promise<IQuizQuestionsHistory> {
|
|
|
|
|
return await fetch(
|
|
|
|
|
`${baseUrl.QUIZ_SRC}${routes.getQuizQuestionHistory(id)}`,
|
|
|
|
|
{
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}
|
|
|
|
|
).then((res) => res.json().then((res) => res as any));
|
2024-08-19 12:44:56 +00:00
|
|
|
}
|
|
|
|
|
|
2024-12-23 19:13:36 +00:00
|
|
|
public static async getQuizWinners(
|
|
|
|
|
id: number
|
|
|
|
|
): Promise<IQuizQuestionsWinners> {
|
|
|
|
|
return await fetch(
|
|
|
|
|
`${baseUrl.QUIZ_SRC}${routes.getQuizQuestionsWinners(id)}`,
|
|
|
|
|
{
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}
|
|
|
|
|
).then((res) => res.json().then((res) => res as IQuizQuestionsWinners));
|
2024-08-19 12:44:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ======================================================================================
|
|
|
|
|
|
|
|
|
|
// Votes ================================================================================
|
|
|
|
|
public static async getAllVotes(): Promise<IAllVotes> {
|
|
|
|
|
return await fetch(`${baseUrl.QUIZ_SRC}${routes.allVotes}`, {
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}).then((res) => res.json().then((res) => res as IAllVotes));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async getVote(vote_id: string): Promise<IVote> {
|
|
|
|
|
return await fetch(`${baseUrl.QUIZ_SRC}${routes.vote(vote_id)}`, {
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}).then((res) => res.json().then((res) => res as IVote));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ============================================================================================
|
|
|
|
|
|
|
|
|
|
// Sms ========================================================================================
|
|
|
|
|
public static async getAdmins(): Promise<IMyTvAdmins> {
|
2024-12-23 19:13:36 +00:00
|
|
|
const token = localStorage.getItem("access_token");
|
2024-08-19 12:44:56 +00:00
|
|
|
|
|
|
|
|
return await fetch(`${baseUrl.SMS_SRC}${routes.myTvAdmins}`, {
|
|
|
|
|
headers: { Authorization: `Bearer ${token}` },
|
|
|
|
|
}).then((res) => res.json().then((res) => res as IMyTvAdmins));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async getMessages(
|
|
|
|
|
id: number,
|
|
|
|
|
current_page: number,
|
|
|
|
|
dateValue: string,
|
|
|
|
|
activeSort: string,
|
2024-12-23 19:13:36 +00:00
|
|
|
searchFetch: string
|
2024-08-19 12:44:56 +00:00
|
|
|
): Promise<MessagesByTvAdmin> {
|
2024-12-23 19:13:36 +00:00
|
|
|
const token = localStorage.getItem("access_token");
|
2024-08-19 12:44:56 +00:00
|
|
|
|
|
|
|
|
return await fetch(
|
2024-12-23 19:13:36 +00:00
|
|
|
`${baseUrl.SMS_SRC}${routes.messagesByTvAdmin(
|
|
|
|
|
id
|
|
|
|
|
)}?per_page=60&page=${current_page}${
|
|
|
|
|
dateValue ? "&filter_by_date=" + dateValue.toString() : ""
|
|
|
|
|
}${searchFetch ? "&search=" + searchFetch : ""}&order=${activeSort}`,
|
2024-08-19 12:44:56 +00:00
|
|
|
{
|
|
|
|
|
headers: { Authorization: `Bearer ${token}` },
|
2024-12-23 19:13:36 +00:00
|
|
|
}
|
2024-08-19 12:44:56 +00:00
|
|
|
).then((res) => res.json().then((res) => res as MessagesByTvAdmin));
|
|
|
|
|
}
|
2024-12-07 11:49:50 +00:00
|
|
|
|
|
|
|
|
// ============================================================================================
|
2024-08-19 12:44:56 +00:00
|
|
|
}
|
2025-02-08 09:02:21 +00:00
|
|
|
|
|
|
|
|
export const getTossData = async ({
|
|
|
|
|
type,
|
|
|
|
|
id,
|
|
|
|
|
}: {
|
|
|
|
|
type: string;
|
|
|
|
|
id: string;
|
|
|
|
|
}) => {
|
|
|
|
|
try {
|
2025-02-10 13:23:33 +00:00
|
|
|
const res = await fetch(`${baseUrl.QUIZ_SRC}${routes.tossId(type, id)}`, {
|
|
|
|
|
next: {
|
|
|
|
|
revalidate: 300,
|
|
|
|
|
tags: ["lotteryData"],
|
|
|
|
|
},
|
|
|
|
|
});
|
2025-02-08 09:02:21 +00:00
|
|
|
|
|
|
|
|
if (!res.ok) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const result = await res.json();
|
|
|
|
|
return result;
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.log(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
2025-02-25 16:29:54 +00:00
|
|
|
|
|
|
|
|
export const getQuizWinnersById = async (id: number) => {
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetch(
|
|
|
|
|
`${baseUrl.QUIZ_SRC}${routes.getQuizQuestionsWinners(id)}`,
|
|
|
|
|
{
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const result = await res.json();
|
|
|
|
|
console.log(result);
|
|
|
|
|
|
|
|
|
|
return result as IQuizQuestionsWinners;
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.log(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getNextQuizWinnners = async (
|
|
|
|
|
id: number,
|
|
|
|
|
limit: number,
|
|
|
|
|
offset: number
|
|
|
|
|
) => {
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetch(
|
|
|
|
|
`${baseUrl.QUIZ_SRC}${routes.getQuizQuestionsWinners(
|
|
|
|
|
id
|
|
|
|
|
)}?limit=${limit}&offset=${offset}`,
|
|
|
|
|
{
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const result = await res.json();
|
|
|
|
|
console.log(result);
|
|
|
|
|
|
|
|
|
|
return result as IQuizQuestionsWinners;
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.log(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
2025-02-27 11:13:29 +00:00
|
|
|
|
|
|
|
|
export const getPlaylistById = async (id: string) => {
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetch(
|
|
|
|
|
`${baseUrl.MATERIALS_SRC}${routes.videos(
|
|
|
|
|
`?per_page=8&page=1&category_id=${id}`
|
|
|
|
|
)}`,
|
|
|
|
|
{
|
|
|
|
|
next: { revalidate: 3600 },
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const result = await res.json();
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.log(err);
|
|
|
|
|
}
|
|
|
|
|
};
|