comty/docs/comty-js/models/post/create-post.md

1.7 KiB

sidebar_position
sidebar_position
8

Create a post

Creates a new post with the given payload.


```js async function PostModel.create(payload) ```

[Object] Payload

Parameter Type Optional Default Description
message String false undefined The message of the post
attachments Array true [] A list of attachments
timestamp String true DateTime.local().toISO()
reply_to String true null

Success Response

Parameter Type Content
data Object post-object

Examples

Basic usage

const post = await PostModel.create({
    message: "Testing Comty.JS",
    timestamp: new Date(),
})

console.log(post)

// result: {
//  _id_: "0000",
//  message: "Testing Comty.JS",
//  timestamp: "2024-01-01T17:00:00.000Z",
// }

Add attachments

const post = await PostModel.create({
    message: "Look at this fox",
    attachments: [
        {
            url: "https://upload.wikimedia.org/wikipedia/commons/3/30/Vulpes_vulpes_ssp_fulvus.jpg",
        }
    ],
})

console.log(post)

// result: {
//  _id_: "0001",
//  message: "Look at this fox",
//  timestamp: "2024-01-01T17:00:00.000Z",
//  attachments: [
//    {
//      url: "https://upload.wikimedia.org/wikipedia/commons/3/30/Vulpes_vulpes_ssp_fulvus.jpg",
//    } 
//  ]
// }

Reply to a post

const post = await PostModel.create({
    reply_to: "0001",
    message: "* pet pet *",
})

console.log(post)

// result: {
//  _id_: "0002",
//  reply_to: "0001",
//  message: "* pat pat*",
//  timestamp: "2024-01-01T17:30:00.000Z",
// }