# Interview
## Task 1
What is wrong?

## Task 2
File
```
module.exports = async (botId, entityId) => {
const bot = await helper.Bot.findOne({ botId }).exec();
if (bot) {
const project = await helper.Project.findOne({ projectId: bot.projectId }).exec();
if (project) {
const entity = await helper.Entity.findOne({ entityId }).exec();
if (entity) {
return { bot, entity, project };
}
throw new Error('Somethings go wrong ');
}
throw new Error('Somethings go wrong ');
}
throw new Error('Somethings go wrong ');
};
```
## Task 3
Write function to check if number is simple
```
const checkIfNumberSimple(number) {
for (let i =2; i<number; i++) {
if (number%i !==0) {
return false;
}
}
return true;
}
const iiSevenSimpleNumber = checkIfNumberSimple(7)
```
## Task 4
Write function to check if array is sorted
```
const checkSortedArray(arr) {
let max = arr[0];
for (let i = 1; i< arr.length; i++) {
if (arr[i]> max ) {
max = arr[i]
} else {
return false;
}
}
return true;
}
const isSorted = (arr) => {
const check = arr[0] > arr[1] ? (a,b) => a > b : (a,b) => a < b;
for( let i = 1; i < arr.length - 1; i +=1){
if(!check(arr[i], arr[i+1])) {
return false;
}
}
return true;
}
const a = checkSortedArray([1,5,67,8,2])
```
## Task 5
```
const permission = {
systemUserId: 4,
organizations: {
1: {
roleIds: [45],
systemFunctionIds: {
34: { availablePermissionTypes: [ 'POST' ] }
}
},
2: {
roleIds: [43],
systemFunctionIds: {
56: { availablePermissionTypes: [ 'PUT' ] },
57: { availablePermissionTypes: [ 'DELETE', 'GET' ] }
}
}
},
projects: {
78: {
organizationId: 1,
roleIds: [145],
systemFunctionIds: {
334: { availablePermissionTypes: [ 'POST' ] }
}
}
}
}
```
Перевірити описати перевірку чи даний об'єкт надає доступ для використання функції.
```
const checkPermission = (
systemFunctionId,
level,
permission,
options = { projectId: null, organizationId: null }
) => {
}
```
checkPermission(334, 'project', permission, { projectId: 78 })
checkPermission(34, 'project', permission, { projectId: 78 })
## Task 5
Ситуація: Для старту сервера необхідно 20с. Трафік на сервер починає надходити з моменту npm run start. Необхіодно тримати запити доти поки сервер не почне повноцінно функціонувати. В момент запуску, сервер заспавнить івент у івент емітер.