MCPcopy
hub / github.com/msgbyte/tianji / getShortLinkAccessTimeSeries

Function getShortLinkAccessTimeSeries

src/server/model/shortlink.ts:278–320  ·  view source on GitHub ↗
(
  workspaceId: string,
  shortLinkId: string,
  filter: BaseQueryFilters,
  options: QueryOptions = {}
)

Source from the content-addressed store, hash-verified

276 * Get time series access statistics for a short link
277 */
278export async function getShortLinkAccessTimeSeries(
279 workspaceId: string,
280 shortLinkId: string,
281 filter: BaseQueryFilters,
282 options: QueryOptions = {}
283) {
284 const shortLink = await prisma.shortLink.findFirst({
285 where: {
286 id: shortLinkId,
287 workspaceId,
288 },
289 });
290
291 if (!shortLink) {
292 throw new Error('Short link not found');
293 }
294
295 const { startDate, endDate } = filter;
296 const { timezone = 'utc', unit = 'day' } = options;
297
298 const results = await prisma.$queryRaw<{ date: string; count: BigInt }[]>`
299 SELECT
300 ${getDateQuery('"createdAt"', unit, timezone)} "date",
301 count(*) "count"
302 FROM
303 "ShortLinkAccess"
304 WHERE
305 "shortLinkId" = ${shortLinkId}
306 and "createdAt" between ${startDate}::timestamptz and ${endDate}::timestamptz
307 GROUP BY 1
308 `;
309
310 return getDateArray(
311 results.map((res) => ({
312 date: res.date,
313 count: Number(res.count),
314 })),
315 startDate,
316 endDate,
317 unit,
318 timezone
319 );
320}
321
322/**
323 * Detect device type from user agent

Callers 1

shortlink.tsFile · 0.85

Calls 2

getDateArrayFunction · 0.90
getDateQueryFunction · 0.50

Tested by

no test coverage detected