add functions to map uuids to ip and names to id

This commit is contained in:
HF 2022-08-02 12:50:34 +02:00
parent e9a7ea7262
commit 7ef311cdc7
3 changed files with 33 additions and 1 deletions

View File

@ -7,6 +7,8 @@
import { createLogger, format, transports } from 'winston';
import DailyRotateFile from 'winston-daily-rotate-file';
export const PIXELLOGGER_PREFIX = './log/pixels-';
const logger = createLogger({
level: 'info',
format: format.combine(
@ -22,7 +24,7 @@ export const pixelLogger = createLogger({
format: format.printf(({ message }) => message),
transports: [
new DailyRotateFile({
filename: './log/pixels-%DATE%.log',
filename: `${PIXELLOGGER_PREFIX}%DATE%.log`,
maxFiles: '14d',
utc: true,
colorize: false,

View File

@ -87,4 +87,19 @@ const IPInfo = sequelize.define('IPInfo', {
},
});
export async function getIdsToIps(ips) {
const result = IPInfo.findAll({
attributes: ['ip', 'uuid'],
where: {
ip: ips,
},
raw: true,
});
const ipToIdMap = {};
result.forEach((obj) => {
ipToIdMap[obj.ip] = obj.uuid;
});
return ipToIdMap;
}
export default IPInfo;

View File

@ -181,4 +181,19 @@ export async function findIdByNameOrId(searchString) {
return null;
}
export async function getNamesToIds(ids) {
const result = RegUser.findAll({
attributes: ['id', 'name'],
where: {
id: ids,
},
raw: true,
});
const idToNameMap = {};
result.forEach((obj) => {
idToNameMap[obj.id] = obj.name;
});
return idToNameMap;
}
export default RegUser;