deploy: POST /api/wallets + full swagger
This commit is contained in:
@@ -15,10 +15,29 @@ export const WalletModel = {
|
||||
return db('wallets').where({ user_id: userId });
|
||||
},
|
||||
|
||||
async findByUserAndChain(userId: string, chain: string): Promise<WalletRow | undefined> {
|
||||
return db('wallets').where({ user_id: userId, chain }).first();
|
||||
},
|
||||
|
||||
async createMany(
|
||||
wallets: { user_id: string; chain: string; address: string; derivation_path: string }[]
|
||||
): Promise<WalletRow[]> {
|
||||
const withIds = wallets.map((w) => ({ id: generateUlid(), ...w }));
|
||||
return db('wallets').insert(withIds).returning('*');
|
||||
},
|
||||
|
||||
/**
|
||||
* Insert wallets, on conflict (user_id, chain) update address + derivation_path.
|
||||
* Used by POST /api/wallets — клиент шлёт массив адресов после регистрации в BITOK.
|
||||
*/
|
||||
async upsertMany(
|
||||
wallets: { user_id: string; chain: string; address: string; derivation_path: string }[]
|
||||
): Promise<WalletRow[]> {
|
||||
const withIds = wallets.map((w) => ({ id: generateUlid(), ...w }));
|
||||
return db('wallets')
|
||||
.insert(withIds)
|
||||
.onConflict(['user_id', 'chain'])
|
||||
.merge(['address', 'derivation_path'])
|
||||
.returning('*');
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user