function pigIt(str){
const splitted = str.split(' ');
return splitted.map(el => {
console.log(el)
if(el.length === 1 && !new RegExp(/^[a-zA-Zа-яА-Я0-9]+$/).test(str)) return el;
const es = el.split('');
es[es.length] = es[0];
es.splice(0, 1);
return es.join('') + 'ay';
}).join(' ');
}
export async function meetings_controller(req: Request, res: Response, next: NextFunction) {
const users = await query('users');
const meetings = await query('meetings');
const response = await meetings.collection.find({members: { $in: [res.locals['user'].id]}}).toArray();
for(let i = 0; i < response.length; i++) {
for(let m = 0; m < response[i]['members'].length; m++) {
response[i]['members'][m] = await users.collection.findOne({id: response[i]['members'][m]});
}
}
console.log(response);
res.send({
message: response
});
}
export async function meetings_controller(req: Request, res: Response, next: NextFunction) {
const users = await query('users');
const meetings = await query('meetings');
const response = await meetings.collection.find({members: { $in: [res.locals['user'].id]}}).toArray();
for(let i = 0; i < response.length; i++) {
for(let m = 0; m < response[i]['members'].length; m++) {
response[i]['members'][m] = await users.collection.findOne({id: response[i]['members'][m]});
}
}
console.log(response);
res.send({
message: response
});
}
export async function meetings_controller(req: Request, res: Response, next: NextFunction) {
const users = await query('users');
const meetings = await query('meetings');
const response = await meetings.collection.find({members: { $in: [res.locals['user'].id]}}).toArray();
for(let i = 0; i < response.length; i++) {
for(let m = 0; m < response[i]['members'].length; m++) {
response[i]['members'][m] = await users.collection.findOne({id: response[i]['members'][m]});
}
}
console.log(response);
res.send({
message: response
});
}
const users = await query('users');
query('meetings').then(async data => {
const response = await data.collection.find({members: { $in: [res.locals['user'].id]}}).toArray();
const result = response.map(meeting => {
const members = meeting['members'].map((member_id: string) => {
return users.collection.findOne({id: member_id});
});
return {
...meeting,
members
}
});
console.log(result);
res.send({
message: result
});
});
members: [Promise, Promise]
const users = query('users');
query('meetings').then(async data => {
const response = await data.collection.find({members: { $in: [res.locals['user'].id]}}).toArray();
const result = response.map(meeting => {
const members: any[] = [];
meeting['members'].forEach((user_id: string, i: number) => {
users.then(data => {
return data.collection.findOne({id: user_id});
}).then(user => members.push(user)).catch(console.error);
});
return {
...meeting,
members
}
});
console.log(result);
res.send({
message: result
});
});
query('meetings').then(async data => {
const response = await data.collection.find({members: { $in: [res.locals['user'].id]}}).toArray();
const result = response.map(meeting => {
const members: any[] = [];
meeting['members'].forEach((user_id: string, i: number) => {
query('users').then(data => {
return data.collection.findOne({id: user_id});
}).then(user => members.push(user)).catch(console.error);
});
return {
...meeting,
members
}
});
console.log(result);
res.send({
message: result
});
});