@culturefy/shared 1.0.32 → 1.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,99 +1,101 @@
1
1
  import { Types } from "mongoose";
2
2
  import { InvocationContext } from "@azure/functions";
3
- import IUser, { UserModel } from "../models/user.model";
3
+ import IUser
4
+ // { UserModel }
5
+ from "../models/user.model";
4
6
  import { Initializers, WithDb } from "@culturefy/shared";
5
7
 
6
8
  export class UserService extends Initializers {
7
9
 
8
- private readonly schema = UserModel.schema;
10
+ // private readonly schema = UserModel.schema;
9
11
  constructor(context: InvocationContext, dbUrl:string) {
10
12
  super(context, dbUrl);
11
13
  }
12
14
 
13
- private getModel() {
14
- const connection = (this as any).getConnection();
15
- if (!connection) {
16
- throw new Error('Database connection not established');
17
- }
18
- return connection.model(UserModel.modelName, this.schema);
19
- }
15
+ // private getModel() {
16
+ // const connection = (this as any).getConnection();
17
+ // if (!connection) {
18
+ // throw new Error('Database connection not established');
19
+ // }
20
+ // return connection.model(UserModel.modelName, this.schema);
21
+ // }
20
22
 
21
- @WithDb
22
- async getUserById(userId: string): Promise<IUser | null> {
23
- try {
24
- let model = this.getModel();
25
- this.context.log("UserId:", JSON.stringify(userId));
23
+ // @WithDb
24
+ // async getUserById(userId: string): Promise<IUser | null> {
25
+ // try {
26
+ // let model = this.getModel();
27
+ // this.context.log("UserId:", JSON.stringify(userId));
26
28
 
27
- // Handle both string and SchemaObjectId inputs
28
- let objectId: Types.ObjectId;
29
- if (typeof userId === 'string') {
30
- objectId = new Types.ObjectId(userId);
31
- } else {
32
- // If it's already a SchemaObjectId, extract the string value
33
- const userIdString = (userId as any).path || (userId as any).toString();
34
- objectId = new Types.ObjectId(userIdString);
35
- }
29
+ // // Handle both string and SchemaObjectId inputs
30
+ // let objectId: Types.ObjectId;
31
+ // if (typeof userId === 'string') {
32
+ // objectId = new Types.ObjectId(userId);
33
+ // } else {
34
+ // // If it's already a SchemaObjectId, extract the string value
35
+ // const userIdString = (userId as any).path || (userId as any).toString();
36
+ // objectId = new Types.ObjectId(userIdString);
37
+ // }
36
38
 
37
- this.context.log("ObjectId:", JSON.stringify(objectId));
38
- const user = await model.findById(objectId);
39
- this.context.log("User:", JSON.stringify(user));
40
- return user;
41
- } catch (error) {
42
- this.context.error("Error in getUserById", error);
43
- throw error;
44
- }
45
- }
39
+ // this.context.log("ObjectId:", JSON.stringify(objectId));
40
+ // const user = await model.findById(objectId);
41
+ // this.context.log("User:", JSON.stringify(user));
42
+ // return user;
43
+ // } catch (error) {
44
+ // this.context.error("Error in getUserById", error);
45
+ // throw error;
46
+ // }
47
+ // }
46
48
 
47
- @WithDb
48
- async getUserByBusinessId(businessId: string, email: string): Promise<IUser | null> {
49
- try {
50
- let model = this.getModel();
51
- this.context.log("BusinessId:", JSON.stringify(businessId));
52
- this.context.log("Email:", JSON.stringify(email));
49
+ // @WithDb
50
+ // async getUserByBusinessId(businessId: string, email: string): Promise<IUser | null> {
51
+ // try {
52
+ // let model = this.getModel();
53
+ // this.context.log("BusinessId:", JSON.stringify(businessId));
54
+ // this.context.log("Email:", JSON.stringify(email));
53
55
 
54
- if(!businessId) return null;
55
- if(!email) return null;
56
+ // if(!businessId) return null;
57
+ // if(!email) return null;
56
58
 
57
- businessId = businessId.toLowerCase();
58
- businessId = businessId.trim();
59
+ // businessId = businessId.toLowerCase();
60
+ // businessId = businessId.trim();
59
61
 
60
- email = email.toLowerCase();
61
- email = email.trim();
62
+ // email = email.toLowerCase();
63
+ // email = email.trim();
62
64
 
63
- // Handle both string and SchemaObjectId inputs
64
- let objectId: Types.ObjectId;
65
- if (typeof businessId === 'string') {
66
- objectId = new Types.ObjectId(businessId);
67
- } else {
68
- // If it's already a SchemaObjectId, extract the string value
69
- const businessIdString = (businessId as any).path || (businessId as any).toString();
70
- objectId = new Types.ObjectId(businessIdString);
71
- }
65
+ // // Handle both string and SchemaObjectId inputs
66
+ // let objectId: Types.ObjectId;
67
+ // if (typeof businessId === 'string') {
68
+ // objectId = new Types.ObjectId(businessId);
69
+ // } else {
70
+ // // If it's already a SchemaObjectId, extract the string value
71
+ // const businessIdString = (businessId as any).path || (businessId as any).toString();
72
+ // objectId = new Types.ObjectId(businessIdString);
73
+ // }
72
74
 
73
- this.context.log("ObjectId:", JSON.stringify(objectId));
74
- const user = await model.findOne({ businessId: objectId, email: email });
75
- this.context.log("User:", JSON.stringify(user));
76
- return user;
77
- } catch (error) {
78
- this.context.error("Error in getUserByBusinessId", error);
79
- throw error;
80
- }
81
- }
75
+ // this.context.log("ObjectId:", JSON.stringify(objectId));
76
+ // const user = await model.findOne({ businessId: objectId, email: email });
77
+ // this.context.log("User:", JSON.stringify(user));
78
+ // return user;
79
+ // } catch (error) {
80
+ // this.context.error("Error in getUserByBusinessId", error);
81
+ // throw error;
82
+ // }
83
+ // }
82
84
 
83
- @WithDb
84
- async getUserByEmail(email: string) {
85
- try {
86
- let model = this.getModel();
87
- this.context.log("Email:", JSON.stringify(email));
85
+ // @WithDb
86
+ // async getUserByEmail(email: string) {
87
+ // try {
88
+ // let model = this.getModel();
89
+ // this.context.log("Email:", JSON.stringify(email));
88
90
 
89
- email = email.toLowerCase();
90
- email = email.trim();
91
- const user = await model.findOne({ email: email });
92
- this.context.log("User:", JSON.stringify(user));
93
- return user;
94
- } catch (error) {
95
- this.context.error("Error in getUserByEmail", error);
96
- throw error;
97
- }
98
- }
91
+ // email = email.toLowerCase();
92
+ // email = email.trim();
93
+ // const user = await model.findOne({ email: email });
94
+ // this.context.log("User:", JSON.stringify(user));
95
+ // return user;
96
+ // } catch (error) {
97
+ // this.context.error("Error in getUserByEmail", error);
98
+ // throw error;
99
+ // }
100
+ // }
99
101
  }