Skip to content

Commit

Permalink
Now invalidating cache whenever user updates a report, fixed filters
Browse files Browse the repository at this point in the history
  • Loading branch information
heythisischris committed Sep 25, 2024
1 parent aa8ccbe commit 31fefee
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/routes/getFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ export const getFilters = async ({ request, reply }) => {
const response = await graphql({
request,
query: `{
messages {
messages(where: {old:{_eq: false}}) {
value: id
label: message
}
tags {
tags(where: {old:{_eq: false}}) {
value: id
label: tag
}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/getReports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const getReports = async ({ request, reply }) => {
const response = await graphql({
request,
query: `query($limit: Int, $offset: Int){
reports: reports_aggregate(limit: $limit, offset: $offset, ${(request.query.reportId) ? `where: { id: {_eq: "${request.query.reportId}"}}` : ''}
reports: reports_aggregate(limit: $limit, offset: $offset, order_by: {updated_at: desc}, ${(request.query.reportId) ? `where: { id: {_eq: "${request.query.reportId}"}}` : ''}
) {
nodes {
id
Expand Down
4 changes: 2 additions & 2 deletions src/routes/updateReports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export const updateReports = async ({ request, reply }) => {
SELECT * FROM "reports" WHERE "id"=$1 AND "user_id"=$2
`, [request.body.reportId, jwtClaims.sub]))?.rows?.[0];
await db.query(`
UPDATE "reports" SET "name"=$1, "filters"=$2 WHERE "id"=$3 AND "user_id"=$4
`, [request.body.reportName ?? original.name, JSON.stringify(request.body.reportFilters ?? original.filters), request.body.reportId, jwtClaims.sub]);
UPDATE "reports" SET "name"=$1, "filters"=$2, "cache_date"=$3 WHERE "id"=$4 AND "user_id"=$5
`, [request.body.reportName ?? original.name, JSON.stringify(request.body.reportFilters ?? original.filters), new Date(), request.body.reportId, jwtClaims.sub]);
await db.clean();

return {
Expand Down

0 comments on commit 31fefee

Please sign in to comment.