Merge pull request #68 from RubenPX/timezone-fixer

Send post using client timestamp
This commit is contained in:
srgooglo 2022-10-13 14:35:41 +02:00 committed by GitHub
commit 6ed3caad77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 8 deletions

View File

@ -38,6 +38,7 @@ export default (props) => {
const cleanPostData = () => { const cleanPostData = () => {
setPostData({ setPostData({
message: "", message: "",
date: new Date(),
additions: [] additions: []
}) })
} }

View File

@ -54,12 +54,13 @@ export default class PostsController extends Controller {
"/post": { "/post": {
middlewares: ["withAuthentication"], middlewares: ["withAuthentication"],
fn: Schematized({ fn: Schematized({
required: ["message"], required: ["message", "date"],
select: ["message", "additions", "type", "data"], select: ["message", "additions", "type", "data", "date"],
}, async (req, res) => { }, async (req, res) => {
const post = await CreatePost({ const post = await CreatePost({
user_id: req.user.id, user_id: req.user.id,
message: req.selection.message, message: req.selection.message,
date: req.selection.date,
additions: req.selection.additions, additions: req.selection.additions,
type: req.selection.type, type: req.selection.type,
data: req.selection.data, data: req.selection.data,

View File

@ -1,18 +1,14 @@
import { Post } from "../../../models" import { Post } from "../../../models"
import getPostData from "./getPostData" import getPostData from "./getPostData"
import momentTimezone from "moment-timezone"
export default async (payload) => { export default async (payload) => {
const { user_id, message, additions, type, data } = payload const { user_id, message, additions, type, data, date } = payload
const current_timezone = momentTimezone.tz.guess()
const created_at = momentTimezone.tz(Date.now(), current_timezone).format()
const post = new Post({ const post = new Post({
user_id: typeof user_id === "object" ? user_id.toString() : user_id, user_id: typeof user_id === "object" ? user_id.toString() : user_id,
message: String(message).toString(), message: String(message).toString(),
additions: additions ?? [], additions: additions ?? [],
created_at: created_at, created_at: date,
type: type, type: type,
data: data, data: data,
}) })