Skip to content

Commit

Permalink
chore : fixing issue : " error Parsing error: Unexpected token 'export'"
Browse files Browse the repository at this point in the history
  • Loading branch information
Mansourkira committed Mar 20, 2024
1 parent 08775c8 commit 1b9f83f
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 989 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"es6": true,
"node": true
},
"parser": "@babel/eslint-parser",
"extends": ["eslint:recommended"],
"rules": {}
}
59 changes: 59 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"scripts": {
"build": "rollup -c --environment BUILD:production",
"dev": "rollup -c -w",
"lint": "eslint --ext .js,.ts www/src",
"lint": "eslint --ext .js,.ts www/src/@sikka/hajar/core",
"test": "jest --config jest.config.js",
"test:watch": "npm run test -- --watch",
"test:coverage": "npm run test -- --coverage",
Expand All @@ -40,6 +40,7 @@
},
"devDependencies": {
"@babel/core": "~7.23.2",
"@babel/eslint-parser": "~7.24.1",
"@babel/plugin-proposal-object-rest-spread": "~7.20.7",
"@babel/preset-env": "~7.23.2",
"@babel/register": "~7.22.15",
Expand Down
3 changes: 1 addition & 2 deletions www/src/@sikka/hajar/core/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-ignore
import { Models } from "../index"; // Adjust the path as needed
import bcrypt from "bcrypt";
import jwt from "jsonwebtoken";
Expand All @@ -11,7 +10,7 @@ export async function login(
email: string,
password: string
): Promise<string> {
const user = await models.User.findOne({ email });
const user: any = await models.User.findOne({ email });
if (!user) {
throw new Error("User not found");
}
Expand Down
41 changes: 18 additions & 23 deletions www/src/@sikka/hajar/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import { login } from "./auth";
import { Model, Document } from "mongoose";

//@Todo : move this to a separate file
export type Models = {
User: any;
Admin: any;
Client: any;
User: Model<Document<any>>;
Admin: Model<Document<any>>;
Client: Model<Document<any>>;
};

export type Config = {
secret: string;
mongoose: any;
};
const initmodesl = {
User: null,
Admin: null,
Client: null,
};

class Hajar {
models: Models;
models!: Models;
config!: Config;
initialized: boolean;
auth: {
Expand All @@ -26,11 +22,6 @@ class Hajar {

constructor() {
this.initialized = false;
this.models = initmodesl;
this.config = {
secret: "",
mongoose: null,
};
this.auth = {
login: (email: string, password: string) =>
login(this.models, this.config, email, password),
Expand All @@ -40,19 +31,23 @@ class Hajar {
initHajar(
jwtSecret: string,
mongooseInstance: any,
userModel: any,
adminModel: any,
clientModel: any
userModel: Model<Document<any>>,
adminModel: Model<Document<any>>,
clientModel: Model<Document<any>>
) {
if (this.initialized) {
throw new Error("Hajar is already initialized");
}

this.models.User = userModel;
this.models.Admin = adminModel;
this.models.Client = clientModel;
this.config.secret = jwtSecret;
this.config.mongoose = mongooseInstance;
this.models = {
User: userModel,
Admin: adminModel,
Client: clientModel,
};
this.config = {
secret: jwtSecret,
mongoose: mongooseInstance,
};
this.initialized = true;

console.log("Hajar initialized successfully.");
Expand Down
Loading

0 comments on commit 1b9f83f

Please sign in to comment.