| 1 | import { and, desc, eq, notInArray } from 'drizzle-orm' |
| 2 | import { db } |
| 3 | import { media, members |
| 4 | |
| 5 | const listByOrganization = async |
| 6 | return await db |
| 7 | .select() |
| 8 | .from(media) |
| 9 | .where(eq(media |
| 10 | .orderBy(desc(media |
| 11 | } |
| 12 | |
| 13 | const listImagesByOrganization = async |
| 14 | return await db |
| 15 | .select({ |
| 16 | id: media.id |
| 17 | name: media.name |
| 18 | url: media.url |
| 19 | contentType: media.contentType |
| 20 | createdAt: media.createdAt |
| 21 | }) |
| 22 | .from(media) |
| 23 | .where( |
| 24 | and( |
| 25 | eq(media.organizationId |
| 26 | notInArray(members.role |
| 27 | ) |
| 28 | ) |
| 29 | .innerJoin(members, |
| 30 | .innerJoin(users, |
| 31 | .orderBy(desc(media |
| 32 | } |
| 33 | |
| 34 | const getMediaItemByUrl = async |
| 35 | const [mediaItem] |
| 36 | .select() |
| 37 | .from(media) |
| 38 | .where(and(eq |
| 39 | return mediaItem |
| 40 | } |
| 41 | export const mediaService = |
| 42 | listByOrganization, |
| 43 | listImagesByOrganization, |
| 44 | getMediaItemByUrl, |
| 45 | } |