Mirror of https://github.com/roostorg/coop github.com/roostorg/coop
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 557ff54b2b435e5f1e789c6a8a4e1bebf2d7deb6 87 lines 2.2 kB view raw
1import { type Kysely } from 'kysely'; 2import { 3 type HmaServicePg, 4 type HashBank, 5 type CreateHashBankInput, 6 type UpdateHashBankInput, 7} from './dbTypes.js'; 8 9export class HashBankService { 10 constructor(private readonly db: Kysely<HmaServicePg>) {} 11 12 async create(input: CreateHashBankInput): Promise<HashBank> { 13 const result = await this.db 14 .insertInto('public.hash_banks') 15 .values({ 16 name: input.name, 17 hma_name: input.hma_name, 18 description: input.description ?? null, 19 enabled_ratio: input.enabled_ratio, 20 org_id: input.org_id, 21 }) 22 .returningAll() 23 .executeTakeFirstOrThrow(); 24 25 return result; 26 } 27 28 async findById(id: number, orgId: string): Promise<HashBank | null> { 29 const result = await this.db 30 .selectFrom('public.hash_banks') 31 .selectAll() 32 .where('id', '=', id) 33 .where('org_id', '=', orgId) 34 .executeTakeFirst(); 35 36 return result ?? null; 37 } 38 39 async findByName(name: string, orgId: string): Promise<HashBank | null> { 40 const result = await this.db 41 .selectFrom('public.hash_banks') 42 .selectAll() 43 .where('name', '=', name) 44 .where('org_id', '=', orgId) 45 .executeTakeFirst(); 46 47 return result ?? null; 48 } 49 50 async findAllByOrgId(orgId: string): Promise<HashBank[]> { 51 const results = await this.db 52 .selectFrom('public.hash_banks') 53 .selectAll() 54 .where('org_id', '=', orgId) 55 .execute(); 56 57 return results; 58 } 59 60 async update(id: number, orgId: string, updates: UpdateHashBankInput): Promise<HashBank> { 61 const result = await this.db 62 .updateTable('public.hash_banks') 63 .set(updates) 64 .where('id', '=', id) 65 .where('org_id', '=', orgId) 66 .returningAll() 67 .executeTakeFirstOrThrow(); 68 69 return result; 70 } 71 72 async delete(id: number, orgId: string): Promise<void> { 73 await this.db 74 .deleteFrom('public.hash_banks') 75 .where('id', '=', id) 76 .where('org_id', '=', orgId) 77 .execute(); 78 } 79 80 async deleteByName(name: string, orgId: string): Promise<void> { 81 await this.db 82 .deleteFrom('public.hash_banks') 83 .where('name', '=', name) 84 .where('org_id', '=', orgId) 85 .execute(); 86 } 87}