mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
Merge pull request #68 from RubenPX/timezone-fixer
Send post using client timestamp
This commit is contained in:
commit
6ed3caad77
@ -38,6 +38,7 @@ export default (props) => {
|
|||||||
const cleanPostData = () => {
|
const cleanPostData = () => {
|
||||||
setPostData({
|
setPostData({
|
||||||
message: "",
|
message: "",
|
||||||
|
date: new Date(),
|
||||||
additions: []
|
additions: []
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -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,
|
||||||
|
@ -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,
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user