Add scheduleregdww5sudfw side ddd n
This commit is contained in:
parent
d9d3f05933
commit
1427a76b9c
@ -1,6 +1,7 @@
|
|||||||
import dbConnect from "@/database/dbConnect";
|
import dbConnect from "@/database/dbConnect";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import workerModel from "@/database/models/workerModel";
|
import workerModel from "@/database/models/workerModel";
|
||||||
|
import mongoose from 'mongoose';
|
||||||
|
|
||||||
// POST METHOD
|
// POST METHOD
|
||||||
export async function POST(req:Request)
|
export async function POST(req:Request)
|
||||||
@ -96,7 +97,7 @@ export async function GET(req:Request)
|
|||||||
{
|
{
|
||||||
try{
|
try{
|
||||||
// connect to the db
|
// connect to the db
|
||||||
dbConnect();
|
await dbConnect();
|
||||||
// get the parms
|
// get the parms
|
||||||
const { searchParams } = new URL(req.url)
|
const { searchParams } = new URL(req.url)
|
||||||
const type = searchParams.get('type')
|
const type = searchParams.get('type')
|
||||||
@ -124,7 +125,7 @@ export async function GET(req:Request)
|
|||||||
else if(type == 'search')
|
else if(type == 'search')
|
||||||
{
|
{
|
||||||
// get the searchKeyword param
|
// get the searchKeyword param
|
||||||
let searchKeyword = searchParams.get('searchKeyword')
|
let searchKeyword = searchParams.get('searchKeyword') || '';
|
||||||
// get the search results docs
|
// get the search results docs
|
||||||
let results = await workerModel.find({
|
let results = await workerModel.find({
|
||||||
$or: [
|
$or: [
|
||||||
@ -144,13 +145,28 @@ export async function GET(req:Request)
|
|||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
success: true,
|
success: true,
|
||||||
message: "docsGetedSuccessfully",
|
message: "docsGetedSuccessfully",
|
||||||
data: responseData ? responseData : [],
|
data: responseData,
|
||||||
}, {
|
}, {
|
||||||
status: 200,
|
status: 200,
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json"
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
// Handle case when type is not provided or is invalid
|
||||||
|
return NextResponse.json({
|
||||||
|
success: false,
|
||||||
|
message: "invalidRequestType",
|
||||||
|
}, {
|
||||||
|
status: 400,
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json"
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}catch(e)
|
}catch(e)
|
||||||
{
|
{
|
||||||
|
console.error("Error in workers GET:", e);
|
||||||
// catch any error and return an error response
|
// catch any error and return an error response
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
success: false,
|
success: false,
|
||||||
@ -168,14 +184,40 @@ export async function DELETE(req:Request)
|
|||||||
{
|
{
|
||||||
try{
|
try{
|
||||||
// connect to the db
|
// connect to the db
|
||||||
dbConnect();
|
await dbConnect();
|
||||||
// get the parms
|
// get the parms
|
||||||
const { searchParams } = new URL(req.url)
|
const { searchParams } = new URL(req.url)
|
||||||
const page = searchParams.get('page'),
|
const page = searchParams.get('page'),
|
||||||
_id : string | null = searchParams.get('_id'),
|
_id : string | null = searchParams.get('_id'),
|
||||||
range : number[] = [(parseInt(page?page : '0') - 1) * 4 , 4];
|
range : number[] = [(parseInt(page?page : '0') - 1) * 4 , 4];
|
||||||
|
|
||||||
|
if (!_id) {
|
||||||
|
return NextResponse.json({
|
||||||
|
success: false,
|
||||||
|
message: "missingId",
|
||||||
|
}, {
|
||||||
|
status: 400,
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// delete the doc
|
// delete the doc
|
||||||
await workerModel.findByIdAndRemove(_id)
|
const deleteResult = await workerModel.findByIdAndRemove(_id);
|
||||||
|
|
||||||
|
if (!deleteResult) {
|
||||||
|
return NextResponse.json({
|
||||||
|
success: false,
|
||||||
|
message: "workerNotFound",
|
||||||
|
}, {
|
||||||
|
status: 404,
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// get the docs by page
|
// get the docs by page
|
||||||
const docs = await workerModel.find({}).skip(range[0]).limit(range[1]),
|
const docs = await workerModel.find({}).skip(range[0]).limit(range[1]),
|
||||||
// get the size of the docs
|
// get the size of the docs
|
||||||
@ -183,14 +225,20 @@ export async function DELETE(req:Request)
|
|||||||
// prepare the return data
|
// prepare the return data
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
success: true,
|
success: true,
|
||||||
message: "docsGetedSuccessfully",
|
message: "workerDeletedSuccessfully",
|
||||||
data: {
|
data: {
|
||||||
docs,
|
docs,
|
||||||
docs_count,
|
docs_count,
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
status: 200,
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json"
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}catch(e)
|
}catch(e)
|
||||||
{
|
{
|
||||||
|
console.error("Error in workers DELETE:", e);
|
||||||
// catch any error and return an error response
|
// catch any error and return an error response
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
success: false,
|
success: false,
|
||||||
@ -208,9 +256,22 @@ export async function PUT(req:Request)
|
|||||||
{
|
{
|
||||||
try{
|
try{
|
||||||
// connect to the db
|
// connect to the db
|
||||||
dbConnect();
|
await dbConnect();
|
||||||
// get the request payload
|
// get the request payload
|
||||||
const { payload } = await req.json();
|
const { payload } = await req.json();
|
||||||
|
|
||||||
|
if (!payload || !payload._id) {
|
||||||
|
return NextResponse.json({
|
||||||
|
success: false,
|
||||||
|
message: "missingRequiredFields",
|
||||||
|
}, {
|
||||||
|
status: 400,
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// get data from formData
|
// get data from formData
|
||||||
const firstName : string | null = payload.firstName as string | null,
|
const firstName : string | null = payload.firstName as string | null,
|
||||||
lastName : string | null = payload.lastName as string | null,
|
lastName : string | null = payload.lastName as string | null,
|
||||||
@ -221,6 +282,7 @@ export async function PUT(req:Request)
|
|||||||
email : string | null = payload.email as string | null,
|
email : string | null = payload.email as string | null,
|
||||||
address : string | null = payload.address as string | null,
|
address : string | null = payload.address as string | null,
|
||||||
_id : string | null = payload._id as string | null;
|
_id : string | null = payload._id as string | null;
|
||||||
|
|
||||||
// update the doc
|
// update the doc
|
||||||
let updated_doc = await workerModel.findByIdAndUpdate(_id, {
|
let updated_doc = await workerModel.findByIdAndUpdate(_id, {
|
||||||
firstName,
|
firstName,
|
||||||
@ -231,7 +293,20 @@ export async function PUT(req:Request)
|
|||||||
phone,
|
phone,
|
||||||
email,
|
email,
|
||||||
address
|
address
|
||||||
}, { new: true })
|
}, { new: true });
|
||||||
|
|
||||||
|
if (!updated_doc) {
|
||||||
|
return NextResponse.json({
|
||||||
|
success: false,
|
||||||
|
message: "workerNotFound",
|
||||||
|
}, {
|
||||||
|
status: 404,
|
||||||
|
headers: {
|
||||||
|
"content-type": "application/json"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// return the success response
|
// return the success response
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
success: true,
|
success: true,
|
||||||
@ -245,6 +320,7 @@ export async function PUT(req:Request)
|
|||||||
})
|
})
|
||||||
}catch(e)
|
}catch(e)
|
||||||
{
|
{
|
||||||
|
console.error("Error in workers PUT:", e);
|
||||||
// catch any error and return an error response
|
// catch any error and return an error response
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
success: false,
|
success: false,
|
||||||
|
|||||||
@ -33,6 +33,16 @@ type SettingsState = {
|
|||||||
loadedFirstTime: boolean,
|
loadedFirstTime: boolean,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add this to your settings slice
|
||||||
|
const initialState = {
|
||||||
|
value: {
|
||||||
|
authRedirectPage: '/dashboard',
|
||||||
|
// Add default values for all settings
|
||||||
|
currencySymbol: '$', // Default currency symbol
|
||||||
|
// Add other default settings here
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
value: {
|
value: {
|
||||||
authRedirectPage: '/dashboard',
|
authRedirectPage: '/dashboard',
|
||||||
|
|||||||
16
webapp/src/utils/i18nFallback.ts
Normal file
16
webapp/src/utils/i18nFallback.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
/**
|
||||||
|
* Utility function to safely access translations with fallbacks
|
||||||
|
*/
|
||||||
|
export function safeTranslation(t: any, key: string, fallback: string = '') {
|
||||||
|
try {
|
||||||
|
const translation = t(key);
|
||||||
|
// If the translation returns the key itself or contains "MISSING", use fallback
|
||||||
|
if (translation === key || translation.includes('MISSING')) {
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
return translation;
|
||||||
|
} catch (error) {
|
||||||
|
console.warn(`Translation error for key "${key}":`, error);
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user