mirror of
https://github.com/R0m1k3/Socialflow.git
synced 2026-10-11 17:26:45 +02:00
Add ability to edit scheduled social media posts
Implement functionality to edit scheduled posts, including date, time, and target page. Introduces a new dialog component for editing and updates the API to support PATCH requests for scheduled posts. Replit-Commit-Author: Agent Replit-Commit-Session-Id: ae4037a0-2a6f-4530-9bac-79b543286bda Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/397bca8c-984f-43ff-841a-10897aeb8140/ae4037a0-2a6f-4530-9bac-79b543286bda/ER8Naji
This commit is contained in:
1 parent
0435a442bd
commit
ce8da4dafe
4 files changed
+226
-12
No files matched your search
+38
-1
@@ -9,7 +9,7 @@ import { z } from "zod";
|
||||
import { openRouterService } from "./services/openrouter";
|
||||
import { cloudinaryService } from "./services/cloudinary";
|
||||
import { insertPostSchema, insertScheduledPostSchema, insertSocialPageSchema, insertAiGenerationSchema, insertCloudinaryConfigSchema, updateCloudinaryConfigSchema, insertOpenrouterConfigSchema, updateOpenrouterConfigSchema, insertUserSchema, postMedia, type SocialPage } from "@shared/schema";
|
||||
import type { User, InsertUser } from "@shared/schema";
|
||||
import type { User, InsertUser, ScheduledPost } from "@shared/schema";
|
||||
|
||||
const upload = multer({ storage: multer.memoryStorage() });
|
||||
|
||||
@@ -696,6 +696,43 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
}
|
||||
});
|
||||
|
||||
app.patch("/api/scheduled-posts/:id", requireAuth, async (req, res) => {
|
||||
try {
|
||||
const user = req.user as User;
|
||||
const userId = user.id;
|
||||
const { id } = req.params;
|
||||
|
||||
// Verify the scheduled post belongs to the user before updating
|
||||
const scheduledPost = await storage.getScheduledPost(id);
|
||||
if (!scheduledPost) {
|
||||
return res.status(404).json({ error: "Scheduled post not found" });
|
||||
}
|
||||
|
||||
const post = await storage.getPost(scheduledPost.postId);
|
||||
if (!post || post.userId !== userId) {
|
||||
return res.status(403).json({ error: "Unauthorized" });
|
||||
}
|
||||
|
||||
// Only allow updating scheduledAt and pageId
|
||||
const { scheduledAt, pageId } = req.body;
|
||||
const updateData: Partial<ScheduledPost> = {};
|
||||
|
||||
if (scheduledAt) {
|
||||
updateData.scheduledAt = new Date(scheduledAt);
|
||||
}
|
||||
|
||||
if (pageId) {
|
||||
updateData.pageId = pageId;
|
||||
}
|
||||
|
||||
const updated = await storage.updateScheduledPost(id, updateData);
|
||||
res.json(updated);
|
||||
} catch (error) {
|
||||
console.error("Error updating scheduled post:", error);
|
||||
res.status(500).json({ error: "Failed to update scheduled post" });
|
||||
}
|
||||
});
|
||||
|
||||
app.post("/api/scheduled-posts", requireAuth, async (req, res) => {
|
||||
try {
|
||||
const scheduledPostData = insertScheduledPostSchema.parse(req.body);
|
||||
|
||||
Reference in new issue
Block a user