feat(dashboard): setting up layout
This commit is contained in:
@@ -5,13 +5,16 @@ import { Database } from "@/client";
|
||||
import { NotFoundError } from "@/errors";
|
||||
import { Credibility, source } from "@/schema";
|
||||
|
||||
export async function getSources(db: Database) {
|
||||
return db.query.source.findMany();
|
||||
}
|
||||
|
||||
export type CreateSourceParams = {
|
||||
name: string;
|
||||
url: string;
|
||||
displayName?: string;
|
||||
description?: string;
|
||||
credibility: Credibility;
|
||||
updatedAt?: Date;
|
||||
credibility?: Credibility;
|
||||
};
|
||||
|
||||
export async function createSource(db: Database, params: CreateSourceParams) {
|
||||
@@ -23,6 +26,33 @@ export async function createSource(db: Database, params: CreateSourceParams) {
|
||||
return result;
|
||||
}
|
||||
|
||||
export type UpdateSourceParams = {
|
||||
id: string;
|
||||
name?: string;
|
||||
displayName?: string;
|
||||
description?: string;
|
||||
credibility?: Credibility;
|
||||
};
|
||||
|
||||
export async function updateSource(db: Database, params: UpdateSourceParams) {
|
||||
const [result] = await db
|
||||
.update(source)
|
||||
.set({
|
||||
credibility: params.credibility,
|
||||
description: params.description,
|
||||
displayName: params.displayName,
|
||||
name: params.name,
|
||||
})
|
||||
.where(eq(source.id, params.id))
|
||||
.returning();
|
||||
|
||||
if (result === undefined) {
|
||||
throw new NotFoundError(`Source not found`);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
export type DeleteSourceParams = {
|
||||
id: string;
|
||||
};
|
||||
@@ -39,6 +69,12 @@ export async function getSourceByName(db: Database, name: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function getById(db: Database, id: string) {
|
||||
return db.query.source.findFirst({
|
||||
where: eq(source.id, id),
|
||||
});
|
||||
}
|
||||
|
||||
export async function getSourceIdByName(db: Database, name: string): Promise<string> {
|
||||
const result = await db.query.source.findFirst({
|
||||
columns: {
|
||||
|
||||
Reference in New Issue
Block a user