Skip to content

Commit

Permalink
fix oopsies
Browse files Browse the repository at this point in the history
  • Loading branch information
BoogieMonster1O1 committed Jun 15, 2024
1 parent 2505edd commit 206e96f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
17 changes: 11 additions & 6 deletions Sources/App/GraphQL/Relation/Post+Resolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,14 @@ extension Post {

func getAttachments(request: Request, arguments: NoArguments) async throws -> [String] {
let id = try self.requireID()
return try await Attachment.query(on: request.db)
.filter(\.$parentId == id)
.all()
.map { $0.hash }
}
}
do {
return try await Attachment.query(on: request.db)
.filter(\.$parentId == id)
.all()
.map { $0.hash }
} catch {
request.logger.error("Failed to fetch attachments for post \(id): \(String(reflecting: error))")
throw Abort(.internalServerError, reason: "Failed to fetch attachments")
}
}
}
3 changes: 2 additions & 1 deletion Sources/App/Migrations/009_CreateAttachments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ struct CreateAttachments: Migration {
func prepare(on database: Database) -> EventLoopFuture<Void> {
return database.schema("attachments")
.field("id", .string, .required)
.field("parentId", .string, .required)
.field("parent_id", .string)
.field("hash", .string, .required)
.field("created_at", .datetime, .required)
.unique(on: "hash")
.unique(on: "id")
.create()
Expand Down
2 changes: 1 addition & 1 deletion Sources/App/Models/Attachment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Vapor
import Fluent

final class Attachment: Model {
public static let schema = "posts"
public static let schema = "attachments"

@ID(custom: "id", generatedBy: .user)
var id: String?
Expand Down

0 comments on commit 206e96f

Please sign in to comment.