mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Chart component. Update web utils.
This commit is contained in:
parent
f947c7770b
commit
590a70c2ff
6 changed files with 159 additions and 8 deletions
|
|
@ -11,7 +11,7 @@ export const prisma = new PrismaClient({
|
|||
|
||||
prisma.on('query', e => {
|
||||
if (process.env.LOG_QUERY) {
|
||||
console.log(`${e.query} (${e.duration}ms)`);
|
||||
console.log(`${e.params} -> ${e.query} (${e.duration}ms)`);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -113,11 +113,15 @@ export async function getAccount(username = '') {
|
|||
);
|
||||
}
|
||||
|
||||
export async function getPageviews(website_id) {
|
||||
export async function getPageviews(website_id, start_at, end_at) {
|
||||
return runQuery(
|
||||
prisma.pageview.findMany({
|
||||
where: {
|
||||
website_id,
|
||||
created_at: {
|
||||
gte: start_at,
|
||||
lte: end_at,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
|
|
|||
26
lib/web.js
26
lib/web.js
|
|
@ -1,13 +1,31 @@
|
|||
export const post = (url, params) =>
|
||||
export const apiRequest = (method, url, body) =>
|
||||
fetch(url, {
|
||||
method: 'post',
|
||||
method,
|
||||
cache: 'no-cache',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(params),
|
||||
}).then(res => (res.status === 200 ? res.json() : null));
|
||||
body,
|
||||
}).then(res => (res.ok ? res.json() : null));
|
||||
|
||||
function parseQuery(url, params) {
|
||||
const query =
|
||||
params &&
|
||||
Object.keys(params).reduce((values, key) => {
|
||||
if (params[key] !== undefined) {
|
||||
return values.concat(`${key}=${encodeURIComponent(params[key])}`);
|
||||
}
|
||||
return values;
|
||||
}, []);
|
||||
return query.length ? `${url}?${query.join('&')}` : url;
|
||||
}
|
||||
|
||||
export const get = (url, params) => apiRequest('get', parseQuery(url, params));
|
||||
|
||||
export const post = (url, params) => apiRequest('post', url, JSON.stringify(params));
|
||||
|
||||
export const del = (url, params) => apiRequest('del', parseQuery(url, params));
|
||||
|
||||
export const hook = (_this, method, callback) => {
|
||||
const orig = _this[method];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue