this.$axios
.$patch(
process.env.baseUrl + "/api/v1/taste/" + this.$route.params.id,
reqData,
{
headers: {
Authorization: this.$auth.$storage._state["_token.local"]
}
}
)
.then(() => {
this.loading = false;
this.$router.push(`/admin/taste`);
})
.catch((err) => {
if (err.response) {
console.log(
err.response.data.message,
"err.response.data.message"
);
this.$message.error(err.response.data.message);
this.loading = false;
} else if (err.request) {
this.$message.error(err.request);
console.log(err.request, "err.request");
this.loading = false;
}
});
const update = async(req, res) => {
if (!req.headers.authorization) {
res.status(500).json({ status: "error", message: "token invalid" });
} else {
const token = req.headers.authorization.split("Bearer ")[1];
jwt.verify(token, process.env.JWT, async function(err, decoded) {
if (err) {
res.status(500).json({ status: "error", message: "token invalid" });
} else {
try {
await TasteModel.findByIdAndUpdate(req.params.id, req.body);
res
.status(200)
.json({ status: "success", message: "Category was updated" });
} catch (error) {
res.status(500).json({ status: "error", message: error.message });
}
}
});
}
};
const create = async (req, res) => {
if (!req.headers.authorization) {
return res.status(500).json({ status: "error", message: "token absent" });
} else {
const token = req.headers.authorization.split("Bearer ")[1];
jwt.verify(token, process.env.JWT, async function (err, decoded) {
if (err) {
return res
.status(500)
.json({ status: "error", message: "token invalid" });
} else {
try {
await LocationModel.create(req.body);
res.status(201).json({ status: 1, message: "success" });
} catch (error) {
res.status(500).json({ status: 0, message: error.message });
}
}
});
}
};
this.$axios
.$patch(
process.env.baseUrl + "/api/v1/location/" + this.$route.params.id,
reqData,
{
headers: {
Authorization: this.$auth.$storage._state["_token.local"],
},
}
)
.then(() => {
this.loading = false;
this.$router.push(`/admin/location/?slug=${this.slug}`);
})
.catch((err) => {
if (err.response) {
console.log(
err.response.data.message,
"err.response.data.message"
);
this.$message.error(err.response.data.message);
this.loading = false;
} else if (err.request) {
this.$message.error(err.request);
console.log(err.request, "err.request");
this.loading = false;
}
});