Skip to content

Commit

Permalink
[FIX] 알림 읽음 처리 - Timezone Issue
Browse files Browse the repository at this point in the history
[FIX] 알림 읽음 처리 - Timezone Issue
  • Loading branch information
xxeol2 authored Jan 13, 2022
2 parents 3bc19fd + 9f825cb commit 3bf3bd1
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions functions/db/notice.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,35 @@ const _ = require('lodash');
const convertSnakeToCamel = require('../lib/convertSnakeToCamel');

const serviceReadByUserId = async (client, userId) => {
const now = dayjs().add(9, 'hour');
const { rows } = await client.query(
`
UPDATE spark.notification
SET is_read = TRUE, read_at = now(), updated_at = now()
SET is_read = TRUE, read_at = $2, updated_at = $2
WHERE is_read = FALSE
AND is_deleted = FALSE
AND is_service = TRUE
AND receiver_id = $1
RETURNING *
`,
[userId],
[userId, now],
);
return convertSnakeToCamel.keysToCamel(rows);
};

const activeReadByUserId = async (client, userId) => {
const now = dayjs().add(9, 'hour');
const { rows } = await client.query(
`
UPDATE spark.notification
SET is_read = TRUE, read_at = now(), updated_at = now()
SET is_read = TRUE, read_at = $2, updated_at = $2
WHERE is_read = FALSE
AND is_deleted = FALSE
AND is_service = FALSE
AND receiver_id = $1
RETURNING *
`,
[userId],
[userId, now],
);
return convertSnakeToCamel.keysToCamel(rows);
};
Expand Down Expand Up @@ -60,35 +62,37 @@ const deleteNoticeByNoticeId = async (client, noticeId) => {
};

const getServicesByUserId = async (client, userId, lastid, size) => {
const beforeAWeek = dayjs().subtract(7, 'day');
const { rows } = await client.query(
`
SELECT * FROM spark.notification
WHERE receiver_id = $1
AND is_deleted = FALSE
AND is_service = TRUE
AND notification_id < $2
AND created_at > current_timestamp + '-7 days'
AND created_at > $4
ORDER BY notification_id DESC
LIMIT $3
`,
[userId, lastid, size],
[userId, lastid, size, beforeAWeek],
);
return convertSnakeToCamel.keysToCamel(rows);
};

const getActivesByUserId = async (client, userId, lastid, size) => {
const beforeAWeek = dayjs().subtract(7, 'day');
const { rows } = await client.query(
`
SELECT * FROM spark.notification
WHERE receiver_id = $1
AND is_deleted = FALSE
AND is_service = FALSE
AND notification_id < $2
AND created_at > current_timestamp + '-7 days'
AND created_at > $4
ORDER BY notification_id DESC
LIMIT $3
`,
[userId, lastid, size],
[userId, lastid, size, beforeAWeek],
);
return convertSnakeToCamel.keysToCamel(rows);
};
Expand Down

0 comments on commit 3bf3bd1

Please sign in to comment.