(input: {
ip: string;
userAgent: string;
userId: string;
dtrx?: DataTransaction;
})
| 3 | import { getDeviceHash } from 'src/utils/crypto'; |
| 4 | |
| 5 | export async function getUserDevice(input: { |
| 6 | ip: string; |
| 7 | userAgent: string; |
| 8 | userId: string; |
| 9 | |
| 10 | dtrx?: DataTransaction; |
| 11 | }) { |
| 12 | const deviceHash = getDeviceHash({ |
| 13 | ip: input.ip, |
| 14 | userAgent: input.userAgent, |
| 15 | userId: input.userId, |
| 16 | }); |
| 17 | |
| 18 | let device = await DeviceModel.query() |
| 19 | .where('user_id', input.userId) |
| 20 | .where('hash', deviceHash) |
| 21 | .first(); |
| 22 | |
| 23 | if (device == null) { |
| 24 | device = await DeviceModel.query(input.dtrx?.trx).insert({ |
| 25 | user_id: input.userId, |
| 26 | hash: deviceHash, |
| 27 | }); |
| 28 | } |
| 29 | |
| 30 | return device; |
| 31 | } |
no test coverage detected