generated from nhcarrigan/template
All checks were successful
Node.js CI / Lint and Test (push) Successful in 1m11s
39 lines
892 B
TypeScript
39 lines
892 B
TypeScript
/**
|
|
* @copyright nhcarrigan
|
|
* @license Naomi's Public License
|
|
* @author Naomi Carrigan
|
|
*/
|
|
import { Injectable } from "@angular/core";
|
|
|
|
@Injectable({
|
|
providedIn: "root",
|
|
})
|
|
export class AnnouncementsService {
|
|
public constructor() {}
|
|
// eslint-disable-next-line @typescript-eslint/class-methods-use-this -- Getter for static URL.
|
|
private get url(): string {
|
|
return "https://hikari.nhcarrigan.com/api/announcements";
|
|
}
|
|
|
|
public async getAnnouncements(): Promise<
|
|
Array<{
|
|
title: string;
|
|
content: string;
|
|
createdAt: string;
|
|
type: "products" | "community";
|
|
}>
|
|
> {
|
|
const response = await fetch(this.url);
|
|
if (!response.ok) {
|
|
return [];
|
|
}
|
|
|
|
return (await response.json()) as Array<{
|
|
title: string;
|
|
content: string;
|
|
createdAt: string;
|
|
type: "products" | "community";
|
|
}>;
|
|
}
|
|
}
|