10 Descriptive message about your changes
This commit is contained in:
parent
0f7d782cd3
commit
b40ad8ecdb
44
webapp/src/app/api/user/actions/services-all/route.ts
Normal file
44
webapp/src/app/api/user/actions/services-all/route.ts
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import dbConnect from "@/database/dbConnect";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import serviceModel from "@/database/models/serviceModel";
|
||||||
|
|
||||||
|
// GET METHOD - Load all active services without pagination
|
||||||
|
export async function GET(req: Request) {
|
||||||
|
try {
|
||||||
|
// connect to the db
|
||||||
|
await dbConnect();
|
||||||
|
|
||||||
|
// get all active services
|
||||||
|
const docs = await serviceModel.find({ status: "active" }).sort({ addedAt: -1 });
|
||||||
|
|
||||||
|
// prepare the return data
|
||||||
|
return NextResponse.json({
|
||||||
|
success: true,
|
||||||
|
message: "docsGetedSuccessfully",
|
||||||
|
data: {
|
||||||
|
docs,
|
||||||
|
docs_count: docs.length,
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
status: 200,
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
// catch any error and return an error response
|
||||||
|
return NextResponse.json({
|
||||||
|
success: false,
|
||||||
|
message: "serverError",
|
||||||
|
}, {
|
||||||
|
status: 500,
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the revalidate variable
|
||||||
|
export const revalidate = 5;
|
||||||
@ -18,7 +18,7 @@ import * as Yup from "yup";
|
|||||||
import Select from 'react-select'
|
import Select from 'react-select'
|
||||||
import { components } from 'react-select';
|
import { components } from 'react-select';
|
||||||
import searchForServices from "@/functions/requests/members/searchForServices";
|
import searchForServices from "@/functions/requests/members/searchForServices";
|
||||||
import loadAllServices from "@/functions/requests/members/loadAllServices";
|
import loadAllActiveServices from "@/functions/requests/members/loadAllActiveServices";
|
||||||
|
|
||||||
export default function AddPopUp()
|
export default function AddPopUp()
|
||||||
{
|
{
|
||||||
@ -232,7 +232,7 @@ export default function AddPopUp()
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function loadServices() {
|
async function loadServices() {
|
||||||
try {
|
try {
|
||||||
let docs = await loadAllServices();
|
let docs = await loadAllActiveServices();
|
||||||
let options = docs.map((v, i) => {
|
let options = docs.map((v, i) => {
|
||||||
return {value: v._id, label: v.name}
|
return {value: v._id, label: v.name}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import DialogActions from '@mui/material/DialogActions';
|
|||||||
import CircularProgress from '@mui/material/CircularProgress';
|
import CircularProgress from '@mui/material/CircularProgress';
|
||||||
import Select from 'react-select'
|
import Select from 'react-select'
|
||||||
import { components } from 'react-select';
|
import { components } from 'react-select';
|
||||||
import loadAllServices from "@/functions/requests/members/loadAllServices";
|
import loadAllActiveServices from "@/functions/requests/members/loadAllActiveServices";
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
|
|
||||||
export default function UpdateSubPopUp()
|
export default function UpdateSubPopUp()
|
||||||
@ -135,7 +135,7 @@ export default function UpdateSubPopUp()
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function loadServices() {
|
async function loadServices() {
|
||||||
try {
|
try {
|
||||||
let docs = await loadAllServices();
|
let docs = await loadAllActiveServices();
|
||||||
let options = docs.map((v, i) => {
|
let options = docs.map((v, i) => {
|
||||||
return {value: v._id, label: v.name}
|
return {value: v._id, label: v.name}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -0,0 +1,10 @@
|
|||||||
|
import axios from 'axios'
|
||||||
|
import { IServicesSchema } from '@/types/IDB'
|
||||||
|
|
||||||
|
const ACTION_NAME = 'services-all'
|
||||||
|
|
||||||
|
export default async function loadAllActiveServices(): Promise<IServicesSchema[]> {
|
||||||
|
const { data } = await axios.get(`/api/user/actions/${ACTION_NAME}`);
|
||||||
|
const docs: IServicesSchema[] = data.data.docs;
|
||||||
|
return docs;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user