Skip to content

Commit

Permalink
chore: links
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-Liendo committed Aug 6, 2024
1 parent 3989eaf commit 15105d1
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions server/src/repository/Link.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
import database from './database';

import type { ILinkForCreate } from '@linx/shared';
import type { ILink, ILinkForCreate } from '@linx/shared';

export class Link {
static async createLink(link: ILinkForCreate): Promise<string> {
const [id] = await database('links').insert(link).returning('id');
return id;
static async create(link: ILinkForCreate): Promise<string> {
const [id] = await database<ILink>('links').insert(link).returning('id');
return id.id;
}

static async getByShorterName(shorter_name: string): Promise<ILink> {
const [link] = await database<ILink>('links')
.select('*')
.where({ shorter_name: shorter_name });
return link;
}

static async getByID(ID: string): Promise<ILink> {
const [link] = await database<ILink>('links').select('*').where({ id: ID });
return link;
}

static async getUserLinks(userID: string): Promise<ILink[]> {
const links = await database<ILink>('links')
.select('*')
.where({ user_id: userID });
return links;
}
}

0 comments on commit 15105d1

Please sign in to comment.