42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import { Link, LinkQueryParams, PaginatedResponse } from '../types';
|
|
import { findLinkById, findLinkDetailsById, findLinks } from './repository';
|
|
|
|
/**
|
|
* Get links with pagination information
|
|
*/
|
|
export async function getLinks(params: LinkQueryParams): Promise<PaginatedResponse<Link>> {
|
|
// Convert page number to offset
|
|
const { page, limit = 10, ...otherParams } = params;
|
|
const offset = page ? (page - 1) * limit : params.offset || 0;
|
|
|
|
const result = await findLinks({
|
|
...otherParams,
|
|
limit,
|
|
offset
|
|
});
|
|
|
|
return {
|
|
data: result.links,
|
|
pagination: {
|
|
total: result.total,
|
|
limit: result.limit,
|
|
offset: result.offset,
|
|
page: result.page,
|
|
totalPages: result.totalPages
|
|
}
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Get a single link by ID with full details (including statistics)
|
|
*/
|
|
export async function getLinkById(linkId: string): Promise<Link | null> {
|
|
return await findLinkById(linkId);
|
|
}
|
|
|
|
/**
|
|
* Get a single link by ID - only basic info without statistics
|
|
*/
|
|
export async function getLinkDetailsById(linkId: string): Promise<Omit<Link, 'visits' | 'unique_visits'> | null> {
|
|
return await findLinkDetailsById(linkId);
|
|
}
|