Fixed: review add - send add request to api
This commit is contained in:
parent
a57a059c2a
commit
986aca3931
@ -18,6 +18,7 @@ new Docs(
|
|||||||
export async function add_post(req: Request, res: Response) {
|
export async function add_post(req: Request, res: Response) {
|
||||||
try {
|
try {
|
||||||
const data: IReview = req.body;
|
const data: IReview = req.body;
|
||||||
|
data.user_id = res.locals.user._id
|
||||||
const review = new Review(data);
|
const review = new Review(data);
|
||||||
await review.save();
|
await review.save();
|
||||||
res.status(201).json(Log.info(201, "review was added", review));
|
res.status(201).json(Log.info(201, "review was added", review));
|
||||||
|
@ -28,6 +28,14 @@ const schema = new Schema<IReview | any>(
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
|
beer_id: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
user_id: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
timestamps: true,
|
timestamps: true,
|
||||||
|
@ -20,6 +20,7 @@ export const add = yup.object({
|
|||||||
packaging: yup.number().min(1).max(5).required(),
|
packaging: yup.number().min(1).max(5).required(),
|
||||||
sourness: yup.boolean().required(),
|
sourness: yup.boolean().required(),
|
||||||
would_again: yup.boolean().required(),
|
would_again: yup.boolean().required(),
|
||||||
|
user_id: yup.string().notRequired()
|
||||||
});
|
});
|
||||||
export interface IReview extends yup.InferType<typeof add>, mongooseAddition {}
|
export interface IReview extends yup.InferType<typeof add>, mongooseAddition {}
|
||||||
export const addExam: IReview = {
|
export const addExam: IReview = {
|
||||||
|
1
frontend/.gitignore
vendored
1
frontend/.gitignore
vendored
@ -37,3 +37,4 @@ yarn-error.*
|
|||||||
.env
|
.env
|
||||||
|
|
||||||
.vscode/
|
.vscode/
|
||||||
|
*.swp
|
||||||
|
@ -67,7 +67,7 @@ export default function TabLayout() {
|
|||||||
options={{ href: null, title: "Add beer" }}
|
options={{ href: null, title: "Add beer" }}
|
||||||
/>
|
/>
|
||||||
<Tabs.Screen
|
<Tabs.Screen
|
||||||
name="review/add"
|
name="review/add/[beer_id]"
|
||||||
options={{ href: null, title: "Add review" }}
|
options={{ href: null, title: "Add review" }}
|
||||||
/>
|
/>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
@ -87,7 +87,7 @@ export default function Tab() {
|
|||||||
title="Add review"
|
title="Add review"
|
||||||
color={colors.gold}
|
color={colors.gold}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
router.push(`/review/${item._id}`);
|
router.push(`/review/add/${item._id}`);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
Binary file not shown.
@ -7,9 +7,11 @@ import * as ImagePicker from "expo-image-picker";
|
|||||||
import DropDownPicker from "react-native-dropdown-picker";
|
import DropDownPicker from "react-native-dropdown-picker";
|
||||||
const DropdownTheme = require("@components/DropdownTheme");
|
const DropdownTheme = require("@components/DropdownTheme");
|
||||||
import { Platform } from "react-native";
|
import { Platform } from "react-native";
|
||||||
|
import { useLocalSearchParams } from "expo-router";
|
||||||
|
|
||||||
export default function reviewAdd() {
|
export default function reviewAdd() {
|
||||||
// States for each dropdown
|
// States for each dropdown
|
||||||
|
const routeParams = useLocalSearchParams();
|
||||||
const [openFoam, setOpenFoam] = useState(false);
|
const [openFoam, setOpenFoam] = useState(false);
|
||||||
const [openBitterSweetness, setOpenBitterSweetness] = useState(false);
|
const [openBitterSweetness, setOpenBitterSweetness] = useState(false);
|
||||||
const [openTaste, setOpenTaste] = useState(false);
|
const [openTaste, setOpenTaste] = useState(false);
|
||||||
@ -311,6 +313,7 @@ export default function reviewAdd() {
|
|||||||
credentials: "include",
|
credentials: "include",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
beer_id: routeParams.beer_id,
|
||||||
foam: itemFoam,
|
foam: itemFoam,
|
||||||
bitter_sweetness: itemBitter_sweetness,
|
bitter_sweetness: itemBitter_sweetness,
|
||||||
taste: itemTaste,
|
taste: itemTaste,
|
||||||
@ -322,10 +325,12 @@ export default function reviewAdd() {
|
|||||||
const res = await req.json();
|
const res = await req.json();
|
||||||
|
|
||||||
if (res.code == 201 && res.data._id) {
|
if (res.code == 201 && res.data._id) {
|
||||||
window.location.href = `/review/${res.data._id}`;
|
// window.location.href = `/review/${res.data._id}`;
|
||||||
|
// TODO: use react router for redirect
|
||||||
|
alert("Review was added!");
|
||||||
} else {
|
} else {
|
||||||
alert(
|
alert(
|
||||||
"Beer was not added successfully. Please check your data and try again.",
|
"Review was not added successfully. Please check your data and try again.",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user