1- import { Image } from "@prisma/client"
1+ import { Image , Prisma } from "@prisma/client"
22
33import prisma from "../prisma"
44import { DEFAULT_LIMIT , DEFAULT_PAGE , IActionReturn , IGetListResponse } from "../shared/type"
5- import { imageSelect } from "./selects"
5+ import { imageSelect , TImageItem } from "./selects"
66import { IImageFilter , IListImageResponse } from "./type"
77
88export const getImages = async ( options : IImageFilter ) : Promise < IListImageResponse > => {
@@ -15,8 +15,6 @@ export const getImages = async (options: IImageFilter): Promise<IListImageRespon
1515 search,
1616 } = options
1717
18- console . log ( ">>>options" , options )
19-
2018 try {
2119 let where = { }
2220 if ( userId ) {
@@ -37,7 +35,7 @@ export const getImages = async (options: IImageFilter): Promise<IListImageRespon
3735 }
3836
3937 let orderBy = {
40- createdAt : " desc" ,
38+ createdAt : Prisma . SortOrder . desc ,
4139 }
4240
4341 if ( orderByKey && order ) {
@@ -88,6 +86,12 @@ export const getImage = async (id: string): Promise<IActionReturn<Image>> => {
8886 select : imageSelect ,
8987 } )
9088
89+ if ( ! image ) {
90+ return {
91+ error : "NOT_FOUND" ,
92+ }
93+ }
94+
9195 return {
9296 data : image ,
9397 }
@@ -100,7 +104,7 @@ export const getImage = async (id: string): Promise<IActionReturn<Image>> => {
100104
101105export const createImage = async (
102106 data : Omit < Image , "id" | "createdAt" | "updatedAt" >
103- ) : Promise < IActionReturn < Image > > => {
107+ ) : Promise < IActionReturn < TImageItem > > => {
104108 try {
105109 const image = await prisma . image . create ( {
106110 data,
@@ -119,7 +123,7 @@ export const createImage = async (
119123export const updateImage = async (
120124 id : string ,
121125 data : Partial < Omit < Image , "id" | "createdAt" | "updatedAt" > >
122- ) : Promise < IActionReturn < Image > > => {
126+ ) : Promise < IActionReturn < TImageItem > > => {
123127 try {
124128 const image = await prisma . image . update ( {
125129 where : { id } ,
@@ -136,7 +140,7 @@ export const updateImage = async (
136140 }
137141}
138142
139- export const deleteImage = async ( id : string , userId : string ) : Promise < IActionReturn < "" > > => {
143+ export const deleteImage = async ( id : string , userId : string ) : Promise < IActionReturn < Image > > => {
140144 try {
141145 // only owner can delete
142146 const deleteImage = await prisma . image . delete ( {
@@ -145,7 +149,7 @@ export const deleteImage = async (id: string, userId: string): Promise<IActionRe
145149
146150 if ( ! deleteImage ) {
147151 return {
148- error : "Unauthorized " ,
152+ error : "UNAUTHORIZED " ,
149153 }
150154 }
151155
0 commit comments