npm package: @sobtid/fastify-exambank
Description: > Exam bank service
Latest version: 0.3.23

# fastify-exambank
> Exam bank service

## Usage
```
const fastify = require('fastify')()

fastify.register(require('@sobtid/fastify-exambank'), {
  hostUrl:  // exanbank.hosturl,
  appId:    // exanbank.appid
})

fastify.post('/grades', (req, reply) => {
  // some code api
  const grades = fastify.exambank.getGrades()
  reply.send(grades)
})

fastify.listen(3000, err => {
  if (err) throw err
})
```
---

## Data Source
### Exam
```
{
  "id": String,
  "applicationId": String,
  "gradeId": String,
  "subjectId": String,
  "classId": String,
  "subClassId": Array<String>,
  "questions": Array<Question>,
  "categories": Array<{
    "id": String,
    "name": String,
    "amount": Number,
    "gradeId": String,
    "classId": String,
    "subjectId": String,
    "isActive": Boolean,
    "createdAt": Timestamp
  }>,
  "publisher": Object<{
    "id": String,
    "name": String,
    "logo": String<URL>
    "createdAt": Timestamp
  }>
  "name": String,
  "createdBy": Object<{
    "id": String,
    "displayName": String
  }>,
  "totalScore": Number,
  "isActive": Boolean,
  "tesingTime": Number, 
  "testingLimit": Number,
  "testingDurationEnable": Boolean,
  "testingDuration": Object<{
    "start": Timestamp,
    "end": Timestamp
  }>,
  "displaySolution": Object<{
    "score": Boolean,
    "answer": Boolean
  }>,
  "shuffling": Object<{
    "question": Boolean,
    "answer": Boolean
  }>,
  "createdAt": Timestamp,
  "updatedAt": Timestamp
}
```

### Video
```
{
  "id": String,
  "name": String,
  "publisherId": Object<{
    "id": String,
    "name": String,
    "logo": String<URL>
  }>,
  "gradeId": Object<{
    "id": String,
    "name": String
  }>,
  "subjectId": Object<{
    "id": String,
    "name": String
  }>,
  "classId": Object<{
    "id": String,
    "name": String
  }>,
  "subClassId": Object<{
    "id": String,
    "name": String
  }>,
  "previewImage": Object<{
    "smallSize": String,
    "largeSize": String
  }>,
  "file": Object<{
      "md": String,
      "hls": String,
      "hd": String
  }>,
  "createdBy": String
}
```
---
## API List

### List grade
```
fastify.exambank.getGrades()
```

### List subject
```
fastify.exambank.getSubjects(params)
```
```
params = {
  gradeId: String
}
```

### List class
```
fastify.exambank.getClass(params) 
```
```
params = {
  subjectId: String
}
```

### List subclass
```
fastify.exambank.getSubClass(params)
```
```
params = {
  "gradeId": String,
  "subjectId": String,
  "classId": String
}
```

### Update subclass
```
fastify.exambank.updateSubClass(subclassId, data)
```
```
subclassId: String

data = {
  "name": String,
  "isActive": Boolean
}
```

### List Publisher
```
fastify.exambank.getPublishers()
```

### Create Publisher
```
fastify.exambank.createPublisher(params)
```
```
params = {
  "name": String,
  "logo": String // Base64 encode
}
```

### Update Publisher
```
fastify.exambank.updatePublisher(publisherId, params)
```
```
publisherId: String

params = {
  "name": String,
  "logo": String // Base64 encode
}
```

### Delate Publisher
```
fastify.exambank.removePublisher(publisherId)
```
```
publisherId: String
```

### List Exam
```
fastify.exambank.getExams(params)
```
```
// Optional

params = {
  "gradeId": String,
  "subjectId": String,
  "classId": String,
  "publisherId": String,
  "createdBy": String,
  "id": [String] // List examId
}
```

### Exam detail
```
fastify.exambank.getExamDetail(examId)
```
```
examId: String
```

### Update Exam Stat
```
fastify.exambank.sendExamTestingStats(examId, totalScore, testingStatsData)
```
```
examId: String
totalScore: Number // total score of user got from testing
testingStatsData: [
  {
    "type": 'MC',
    "questionId": String,
    "isCorrect": Boolean,
    "timeUsed": Number,
    "answer": [String] // Array of choice id
  },
  {
    "type": 'ST',
    "questionId": String,
    "isCorrect": Boolean,
    "timeUsed": Number,
    "answer": String
  },
  {
    "type": 'MA',
    "questionId": String,
    "isCorrect": Boolean,
    "timeUsed": Number,
    "answer": [
      {
        "id": String, // Left choice id
        "match": String // Right choice id
      }
    ]
  },
  {
    "type": 'SQMC',
    "questionId": String,
    "isCorrect": Boolean,
    "timeUsed": Number,
    "answer": [
      {
        "id": String,
        "answer": [String] // Array of choice id
      }
    ]
  },
  {
    "type": 'SQST',
    "questionId": String,
    "isCorrect": Boolean,
    "timeUsed": Number,
    "answer": [
      {
        "id": String,
        "answer": String
      }
    ]
  }
]
```

### Update Questions Stat
```
fastify.exambank.sendQuestionTestingStats(params)
```
```
params: [
  {
    "type": 'MC',
    "questionId": String,
    "isCorrect": Boolean,
    "timeUsed": Number,
    "answer": [String] // Array of choice id
  },
  {
    "type": 'ST',
    "questionId": String,
    "isCorrect": Boolean,
    "timeUsed": Number,
    "answer": String
  },
  {
    "type": 'MA',
    "questionId": String,
    "isCorrect": Boolean,
    "timeUsed": Number,
    "answer": [
      {
        "id": String, // Left choice id
        "match": String // Right choice id
      }
    ]
  },
  {
    "type": 'SQMC',
    "questionId": String,
    "isCorrect": Boolean,
    "timeUsed": Number,
    "answer": [
      {
        "id": String,
        "answer": [String] // Array of choice id
      }
    ]
  },
  {
    "type": 'SQST',
    "questionId": String,
    "isCorrect": Boolean,
    "timeUsed": Number,
    "answer": [
      {
        "id": String,
        "answer": String
      }
    ]
  }
]
```

### Create user
```
fastify.exambank.createUser(params)
```
```
// Optiona

params = {
  "displayName": String,
  "email": String,
  "password": String,
  "role": String,
  "avatar": String, // Base64 encode
  "publisherId": String
}
```

### Update user
```
fastify.exambank.editUser(userId, params)
```
```
// Optional

userId: String

params = {
  "displayName": String,
  "email": String,
  "password": {
    "old": String,
    "new": String
  },
  "avatar": String, // Base64 encode
  "publisherId": String
}
```

### Question detail
```
fastify.exambank.getQuestionDetail(questionId)
```
```
questionId: String
```

### Total question by type
```
fastify.exambank.getQuestionStats(type)
```
```
type: Enum { grade, type, status }
```

### List random question
```
fastify.exambank.randomQuestions(params)
```
```
// Optional

params = {
  "gradeId": String,
  "subjectId": String,
  "classId": String,
  "subClassIds": String,
  "limit": Number
}
```

### List Bundle
```
fastify.exambank.getBundles(params)
```
```
// Optional

params = {
  "level": String,
  "gradeId": String,
  "subjectId": String,
  "id": [String] // List bundleId
}
```

### Bundle detail
```
fastify.exambank.getBundleDetail(bundleId)
```
```
bundleId: String
```

### Bundle relate
```
fastify.exambank.getBundleRelate(bundleId)
```
```
bundleId: String
```

### List of video
```
fastify.exambank.getVideos(params)
```
```
// Optional

params = {
  "gradeId": String,
  "subjectId": String,
  "classId": String,
  "publisherId: String",
  "createdBy": String
}
```