Skip to content

Commit 2e1b6f5

Browse files
committed
fix: update user handling in Post DTO and model, add Docker Compose restart policy
1 parent 25b638d commit 2e1b6f5

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

backend/src/dtos/post.dto.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class PostResponseDto implements IPostResponse {
6363
if (document.user && typeof document.user === "object") {
6464
dto.user = {
6565
id: document.user._id.toString(),
66-
username: document.user.username || "Unknown",
66+
username: (document.user as unknown as IUserDocument).username || "Unknown",
6767
};
6868
} else {
6969
// If user is not populated, just use the ID

backend/src/models/Post.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ import { EntityId } from "@/types/common.types";
44

55
// Base interface (without Document methods)
66
export interface IPost {
7-
user: {
8-
_id: EntityId;
9-
username: string;
10-
email?: string;
11-
};
7+
user: EntityId;
128
content: string;
139
imageUrl?: string;
1410
likes: EntityId[];
@@ -47,7 +43,7 @@ export interface IPostModel extends Model<IPostDocument> {
4743
const postSchema = new Schema<IPostDocument>(
4844
{
4945
user: {
50-
type: Schema.Types.Mixed,
46+
type: Schema.Types.ObjectId,
5147
ref: "User",
5248
required: true,
5349
},
@@ -154,7 +150,7 @@ postSchema.statics.getRankedPosts = async function (options: {
154150
{ $sort: { score: -1 } }, // Sort by descending score
155151
{ $skip: options.skip },
156152
{ $limit: options.limit },
157-
{
153+
{
158154
$lookup: {
159155
from: "users", // The name of the users collection
160156
localField: "user",
@@ -169,7 +165,7 @@ postSchema.statics.getRankedPosts = async function (options: {
169165
]),
170166
this.countDocuments(),
171167
]);
172-
168+
173169
return { posts, total };
174170
};
175171
// Export the model and return type

docker-compose.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ version: '3.8'
22

33
services:
44
backend:
5+
restart: always
56
build:
67
context: ./backend
78
dockerfile: ../docker/backend.dockerfile
@@ -17,29 +18,28 @@ services:
1718
- RECAPTCHA_SITE_KEY=${RECAPTCHA_SITE_KEY}
1819
- NODE_ENV=${NODE_ENV}
1920
volumes:
20-
- ./backend:/app
2121
- /app/node_modules
2222
depends_on:
2323
- mongodb
2424
networks:
2525
- app-network
2626

2727
frontend:
28+
restart: always
2829
build:
2930
context: ./frontend
3031
dockerfile: ../docker/frontend.dockerfile
3132
ports:
3233
- "${FRONTEND_PORT:-3000}:${FRONTEND_PORT:-3000}"
3334
env_file:
3435
- ./frontend/.env
35-
volumes:
36-
- ./frontend:/app # Only mount for development purposes
3736
depends_on:
3837
- backend
3938
networks:
4039
- app-network
4140

4241
mongodb:
42+
restart: always
4343
image: mongo:5
4444
environment:
4545
MONGO_INITDB_DATABASE: surge-social
@@ -50,6 +50,7 @@ services:
5050

5151
# Add Nginx reverse proxy for SSL termination
5252
nginx:
53+
restart: always
5354
image: nginx:alpine
5455
ports:
5556
- "80:80"
@@ -65,6 +66,7 @@ services:
6566

6667
# Automatically renew SSL certificates
6768
certbot:
69+
restart: always
6870
image: certbot/certbot
6971
container_name: certbot
7072
volumes:

0 commit comments

Comments
 (0)