mirror of
https://github.com/LukasKanka/api_test.git
synced 2026-11-11 06:34:36 +01:00
fullLocalhostUpdateDateNotNetDownload
This commit is contained in:
1 parent
abbba340c1
commit
c8118d2154
4 files changed
+1142
-1066
No files matched your search
@@ -0,0 +1,25 @@
|
|||||||
|
info:
|
||||||
|
name: Add new sprll
|
||||||
|
type: http
|
||||||
|
seq: 5
|
||||||
|
|
||||||
|
http:
|
||||||
|
method: POST
|
||||||
|
url: http://localhost:3000/spells
|
||||||
|
body:
|
||||||
|
type: json
|
||||||
|
data: |-
|
||||||
|
{
|
||||||
|
"spell":"Fire speed",
|
||||||
|
"effect":"fire speed forever",
|
||||||
|
"type":"Curse",
|
||||||
|
"isUnforgivable":"false"
|
||||||
|
}
|
||||||
|
auth: inherit
|
||||||
|
|
||||||
|
settings:
|
||||||
|
encodeUrl: true
|
||||||
|
timeout: 0
|
||||||
|
followRedirects: true
|
||||||
|
maxRedirects: 5
|
||||||
|
forwardAuthorizationHeader: false
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const spellsFilePath = path.join(__dirname, '../spells.json');
|
||||||
|
|
||||||
var spells = require('../spells.json');
|
var spells = require('../spells.json');
|
||||||
const joi = require('joi');
|
const joi = require('joi');
|
||||||
const initialSpells = require('../spells.json');
|
const initialSpells = JSON.parse(JSON.stringify(require('../spells.json')));
|
||||||
|
|
||||||
const schema = joi.object().keys({
|
const schema = joi.object().keys({
|
||||||
spell: joi.string().min(3).max(30).required().regex(/^\w+(?:\s+\w+)*$/),
|
spell: joi.string().min(3).max(30).required().regex(/^\w+(?:\s+\w+)*$/),
|
||||||
type: joi.string().valid('Charm', 'Enchantment', 'Curse', 'Spell', 'Hex', 'Jinx'),
|
type: joi.string().valid('Charm', 'Enchantment', 'Curse', 'Spell', 'Hex', 'Jinx'),
|
||||||
@@ -11,6 +16,10 @@ const schema = joi.object().keys({
|
|||||||
|
|
||||||
const randomId = require('random-id');
|
const randomId = require('random-id');
|
||||||
|
|
||||||
|
function saveSpellsToFile() {
|
||||||
|
fs.writeFileSync(spellsFilePath, JSON.stringify(spells, null, 2));
|
||||||
|
}
|
||||||
|
|
||||||
exports.spells_list = function (req, res) {
|
exports.spells_list = function (req, res) {
|
||||||
let result = spells;
|
let result = spells;
|
||||||
if (typeof req.query.type !== 'undefined') {
|
if (typeof req.query.type !== 'undefined') {
|
||||||
@@ -29,11 +38,13 @@ exports.spells_list = function (req, res) {
|
|||||||
}
|
}
|
||||||
exports.delete_all = function (req, res) {
|
exports.delete_all = function (req, res) {
|
||||||
spells = [];
|
spells = [];
|
||||||
|
saveSpellsToFile();
|
||||||
res.send({ message: 'Mischief managed' })
|
res.send({ message: 'Mischief managed' })
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.reset = function (req, res) {
|
exports.reset = function (req, res) {
|
||||||
spells = initialSpells.slice(0);
|
spells = JSON.parse(JSON.stringify(initialSpells));
|
||||||
|
saveSpellsToFile();
|
||||||
res.send({ message: 'Aparecium', spells: spells })
|
res.send({ message: 'Aparecium', spells: spells })
|
||||||
}
|
}
|
||||||
exports.specific_spell = function (req, res) {
|
exports.specific_spell = function (req, res) {
|
||||||
@@ -50,6 +61,7 @@ exports.delete_spell = function (req, res) {
|
|||||||
return res.status(404).send({ message: "Spell not found" });
|
return res.status(404).send({ message: "Spell not found" });
|
||||||
}
|
}
|
||||||
spells = spells.filter(spell => spell.id != req.params.spellId);
|
spells = spells.filter(spell => spell.id != req.params.spellId);
|
||||||
|
saveSpellsToFile();
|
||||||
return res.send({
|
return res.send({
|
||||||
message: 'spell deleted'
|
message: 'spell deleted'
|
||||||
});
|
});
|
||||||
@@ -81,12 +93,21 @@ exports.update_spell = function (req, res) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const formattedSpell = {
|
||||||
|
id: value.id,
|
||||||
|
spell: value.spell,
|
||||||
|
type: value.type,
|
||||||
|
effect: value.effect,
|
||||||
|
isUnforgivable: value.isUnforgivable
|
||||||
|
};
|
||||||
|
|
||||||
spells = spells.filter(spell => spell.id != req.params.spellId);
|
spells = spells.filter(spell => spell.id != req.params.spellId);
|
||||||
spells.push(newSpell);
|
spells.push(formattedSpell);
|
||||||
|
saveSpellsToFile();
|
||||||
return res.status(201).json({
|
return res.status(201).json({
|
||||||
message: "Spell updated",
|
message: "Spell updated",
|
||||||
spell: {
|
spell: {
|
||||||
id: newSpell.id
|
id: formattedSpell.id
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -96,11 +117,11 @@ exports.new_spell = function (req, res) {
|
|||||||
var pattern = 'aA0'
|
var pattern = 'aA0'
|
||||||
|
|
||||||
var newSpell = {
|
var newSpell = {
|
||||||
|
id: randomId(len, pattern),
|
||||||
spell: req.body.spell,
|
spell: req.body.spell,
|
||||||
type: req.body.type,
|
type: req.body.type,
|
||||||
effect: req.body.effect,
|
effect: req.body.effect,
|
||||||
isUnforgivable: req.body.isUnforgivable,
|
isUnforgivable: req.body.isUnforgivable
|
||||||
id: randomId(len, pattern)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = spells.find((spell) => spell.spell === newSpell.spell);
|
let result = spells.find((spell) => spell.spell === newSpell.spell);
|
||||||
@@ -121,11 +142,20 @@ exports.new_spell = function (req, res) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
spells.push(newSpell);
|
const formattedSpell = {
|
||||||
|
id: value.id,
|
||||||
|
spell: value.spell,
|
||||||
|
type: value.type,
|
||||||
|
effect: value.effect,
|
||||||
|
isUnforgivable: value.isUnforgivable
|
||||||
|
};
|
||||||
|
|
||||||
|
spells.push(formattedSpell);
|
||||||
|
saveSpellsToFile();
|
||||||
return res.status(201).json({
|
return res.status(201).json({
|
||||||
message: "Spell created",
|
message: "Spell created",
|
||||||
spell: {
|
spell: {
|
||||||
id: newSpell.id
|
id: formattedSpell.id
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
+1078
-1057
File diff suppressed because it is too large.
Load diff
@@ -9,7 +9,7 @@ import QuoteGenerator from "../src/components/QuoteGenerator";
|
|||||||
import GringottsBank from "../src/components/GringottsBank";
|
import GringottsBank from "../src/components/GringottsBank";
|
||||||
|
|
||||||
const axiosconfig = {
|
const axiosconfig = {
|
||||||
baseURL: "https://potterapi-tgq2.onrender.com",
|
baseURL: process.env.VUE_APP_API_URL || "http://localhost:3000",
|
||||||
timeout: 30000,
|
timeout: 30000,
|
||||||
};
|
};
|
||||||
Vue.prototype.$http = axios.create(axiosconfig);
|
Vue.prototype.$http = axios.create(axiosconfig);
|
||||||
|
|||||||
Reference in new issue
Block a user