Track and save on groceries

feat(backend): implement CRUD for stores

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>

+35 -36
+35 -36
apps/backend/src/impl/stores.ts
··· 26 26 }, 27 27 ); 28 28 29 - export const getStore = os.stores.get.handler(async ({ input: { params }, context: { db } }) => { 30 - const store = await db 31 - .select() 32 - .from(storesTable) 33 - .where(eq(storesTable.id, params.id)); 29 + export const getStore = os.stores.get.handler( 30 + async ({ input: { params }, context: { db } }) => { 31 + const store = await db 32 + .select() 33 + .from(storesTable) 34 + .where(eq(storesTable.id, params.id)); 34 35 35 - if (store.length < 1) { 36 - throw new ORPCError("NOT_FOUND", { 37 - message: `Store ${params.id} not found`, 38 - }); 39 - } 36 + if (store.length < 1) { 37 + throw new ORPCError("NOT_FOUND", { 38 + message: `Store ${params.id} not found`, 39 + }); 40 + } 40 41 41 - return { 42 - status: 200, 43 - body: store[0], 44 - }; 45 - }); 42 + return { 43 + status: 200, 44 + body: store[0], 45 + }; 46 + }, 47 + ); 46 48 47 - export const createStore = os.stores.create.handler(async ({ input: { body }, context: { db } }) => { 48 - const store = await db 49 - .insert(storesTable) 50 - .values([ 51 - body 52 - ]) 53 - .returning(); 49 + export const createStore = os.stores.create.handler( 50 + async ({ input: { body }, context: { db } }) => { 51 + const store = await db.insert(storesTable).values([body]).returning(); 54 52 55 - assert(store.length > 0, "Inserted store was returned"); 53 + assert(store.length > 0, "Inserted store was returned"); 56 54 57 - return { 58 - status: 201, 59 - body: store[0], 60 - } 61 - }); 55 + return { 56 + status: 201, 57 + body: store[0], 58 + }; 59 + }, 60 + ); 62 61 63 - export const deleteStore = os.stores.delete.handler(async ({ input: { params }, context: { db } }) => { 64 - await db 65 - .delete(storesTable) 66 - .where(eq(storesTable.id, params.id)); 62 + export const deleteStore = os.stores.delete.handler( 63 + async ({ input: { params }, context: { db } }) => { 64 + await db.delete(storesTable).where(eq(storesTable.id, params.id)); 67 65 68 - return { 69 - status: 204, 70 - }; 71 - }); 66 + return { 67 + status: 204, 68 + }; 69 + }, 70 + ); 72 71 73 72 export const storeRouter = { 74 73 list: listStores,