32 lines
737 B
JavaScript
32 lines
737 B
JavaScript
|
const express = require('express');
|
||
|
const { Minecraft } = require('../functions/models.js');
|
||
|
|
||
|
const router = express.Router();
|
||
|
|
||
|
router.post('/', async (req, res) => {
|
||
|
const { uuid } = req.body;
|
||
|
|
||
|
if (!uuid) return res.status(400).send({ errorMessage: 'UUID is required' });
|
||
|
|
||
|
try {
|
||
|
const minecraftCol = await Minecraft.findOrCreate({
|
||
|
where: { uuid },
|
||
|
defaults: {
|
||
|
code: generateCode().toString(),
|
||
|
},
|
||
|
});
|
||
|
|
||
|
res.send({ code: minecraftCol[0].code });
|
||
|
} catch (error) {
|
||
|
console.log(error);
|
||
|
|
||
|
res.status(500).send({ errorMessage: 'Error while verifing minecraft uuid' });
|
||
|
}
|
||
|
});
|
||
|
|
||
|
const generateCode = () => {
|
||
|
return Math.floor(100000 + Math.random() * 900000);
|
||
|
};
|
||
|
|
||
|
module.exports = router;
|