@iotready/nextjs-components-library 1.0.0-preview22 → 1.0.0-preview23
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.
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@iotready/nextjs-components-library",
|
3
|
-
"version": "1.0.0-
|
3
|
+
"version": "1.0.0-preview23",
|
4
4
|
"main": "index.js",
|
5
5
|
"scripts": {
|
6
6
|
"build": "rm -rf dist && tsc --project tsconfig.build.json && cp package.json dist/",
|
@@ -20,7 +20,7 @@
|
|
20
20
|
"chartjs-plugin-annotation": "^3.1.0",
|
21
21
|
"chartjs-plugin-zoom": "^2.0.1",
|
22
22
|
"csv-parse": "^5.6.0",
|
23
|
-
"firebase": "^
|
23
|
+
"firebase-admin": "^13.4.0",
|
24
24
|
"leaflet": "^1.9.4",
|
25
25
|
"leaflet-defaulticon-compatibility": "^0.1.2",
|
26
26
|
"material-ui-confirm": "^3.0.16",
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
2
|
-
export declare const getAnnotations: (
|
1
|
+
import { Firestore } from "firebase-admin/firestore";
|
2
|
+
export declare const getAnnotations: (db: Firestore, deviceID: number) => Promise<{
|
3
3
|
id: string;
|
4
4
|
}[]>;
|
@@ -1,14 +1,11 @@
|
|
1
1
|
"use server";
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
const annotationsQuery = query(collection(db, "annotations"), where("target", "==", deviceID), orderBy("createdAt", "desc"));
|
10
|
-
const groupsSnapshot = await getDocs(annotationsQuery);
|
11
|
-
return groupsSnapshot.docs.map((doc) => ({
|
2
|
+
export const getAnnotations = async (db, deviceID) => {
|
3
|
+
const annotationsRef = db.collection("annotations");
|
4
|
+
const snapshot = await annotationsRef
|
5
|
+
.where("target", "==", deviceID)
|
6
|
+
.orderBy("createdAt", "desc")
|
7
|
+
.get();
|
8
|
+
return snapshot.docs.map((doc) => ({
|
12
9
|
id: doc.id,
|
13
10
|
...doc.data()
|
14
11
|
}));
|
@@ -1,15 +1,15 @@
|
|
1
|
-
import {
|
2
|
-
export declare const getGroups: (
|
1
|
+
import { Firestore } from "firebase-admin/firestore";
|
2
|
+
export declare const getGroups: (db: Firestore, productID: number, userID?: string) => Promise<{
|
3
3
|
id: string;
|
4
4
|
}[]>;
|
5
|
-
export declare const getGroupById: (
|
5
|
+
export declare const getGroupById: (db: Firestore, id: string) => Promise<{
|
6
6
|
id: string;
|
7
7
|
}>;
|
8
|
-
export declare const createGroup: (
|
9
|
-
export declare const updateGroup: (
|
10
|
-
export declare const deleteGroup: (
|
11
|
-
export declare const getUsersGroup: (
|
8
|
+
export declare const createGroup: (db: Firestore, group: any) => Promise<string>;
|
9
|
+
export declare const updateGroup: (db: Firestore, id: string, group: any) => Promise<any>;
|
10
|
+
export declare const deleteGroup: (db: Firestore, id: string) => Promise<void>;
|
11
|
+
export declare const getUsersGroup: (db: Firestore, groupID: string) => Promise<{
|
12
12
|
id: string;
|
13
13
|
}[]>;
|
14
|
-
export declare const addUsersGroup: (
|
15
|
-
export declare const removeUserGroup: (
|
14
|
+
export declare const addUsersGroup: (db: Firestore, groupID: string, userName: string, userID: string) => Promise<string>;
|
15
|
+
export declare const removeUserGroup: (db: Firestore, groupID: string, userID: string) => Promise<string | undefined>;
|
package/server-actions/groups.js
CHANGED
@@ -1,87 +1,74 @@
|
|
1
1
|
"use server";
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
const db = getFirestore(app);
|
9
|
-
const groupsQuery = query(collection(db, "groups"), where("productID", "==", productID), orderBy("created", "desc"));
|
2
|
+
// 1. GET GROUPS
|
3
|
+
export const getGroups = async (db, productID, userID) => {
|
4
|
+
const groupsRef = db
|
5
|
+
.collection("groups")
|
6
|
+
.where("productID", "==", productID)
|
7
|
+
.orderBy("created", "desc");
|
10
8
|
let groupIds = null;
|
11
9
|
if (userID) {
|
12
|
-
const
|
13
|
-
|
14
|
-
|
10
|
+
const userGroupsSnapshot = await db
|
11
|
+
.collection("userGroups")
|
12
|
+
.where("user.userId", "==", userID)
|
13
|
+
.get();
|
14
|
+
groupIds = userGroupsSnapshot.docs.map((doc) => doc.data().groupId);
|
15
15
|
}
|
16
|
-
const groupsSnapshot = await
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
.map((doc) => ({
|
21
|
-
id: doc.id,
|
22
|
-
...doc.data()
|
23
|
-
}));
|
24
|
-
}
|
25
|
-
return groupsSnapshot.docs.map((doc) => ({
|
16
|
+
const groupsSnapshot = await groupsRef.get();
|
17
|
+
return groupsSnapshot.docs
|
18
|
+
.filter((doc) => !groupIds || groupIds.includes(doc.id))
|
19
|
+
.map((doc) => ({
|
26
20
|
id: doc.id,
|
27
21
|
...doc.data()
|
28
22
|
}));
|
29
23
|
};
|
30
|
-
|
31
|
-
|
32
|
-
const
|
33
|
-
const groupSnapshot = await getDoc(doc(db, "groups", id));
|
24
|
+
// 2. GET GROUP BY ID
|
25
|
+
export const getGroupById = async (db, id) => {
|
26
|
+
const docSnapshot = await db.collection("groups").doc(id).get();
|
34
27
|
return {
|
35
|
-
id:
|
36
|
-
...
|
28
|
+
id: docSnapshot.id,
|
29
|
+
...docSnapshot.data()
|
37
30
|
};
|
38
31
|
};
|
39
|
-
|
40
|
-
|
32
|
+
// 3. CREATE GROUP
|
33
|
+
export const createGroup = async (db, group) => {
|
41
34
|
const newGroup = {
|
42
35
|
...group,
|
43
|
-
created
|
36
|
+
created: new Date().toISOString()
|
44
37
|
};
|
45
|
-
const
|
46
|
-
const db = getFirestore(app);
|
47
|
-
const docRef = await addDoc(collection(db, "groups"), newGroup);
|
38
|
+
const docRef = await db.collection("groups").add(newGroup);
|
48
39
|
return docRef.id;
|
49
40
|
};
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
const groupRef = doc(db, "groups", id);
|
54
|
-
await updateDoc(groupRef, group);
|
41
|
+
// 4. UPDATE GROUP
|
42
|
+
export const updateGroup = async (db, id, group) => {
|
43
|
+
await db.collection("groups").doc(id).update(group);
|
55
44
|
return group;
|
56
45
|
};
|
57
|
-
|
58
|
-
|
59
|
-
const
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
46
|
+
// 5. DELETE GROUP
|
47
|
+
export const deleteGroup = async (db, id) => {
|
48
|
+
const userGroupsSnapshot = await db
|
49
|
+
.collection("userGroups")
|
50
|
+
.where("groupId", "==", id)
|
51
|
+
.get();
|
52
|
+
const batch = db.batch();
|
53
|
+
userGroupsSnapshot.docs.forEach((doc) => {
|
54
|
+
batch.delete(doc.ref);
|
65
55
|
});
|
66
|
-
|
67
|
-
await
|
56
|
+
batch.delete(db.collection("groups").doc(id));
|
57
|
+
await batch.commit();
|
68
58
|
};
|
69
|
-
// USERS
|
70
|
-
export const getUsersGroup = async (
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
return groupsSnapshot.docs.map((doc) => ({
|
59
|
+
// 6. GET USERS GROUP
|
60
|
+
export const getUsersGroup = async (db, groupID) => {
|
61
|
+
const snapshot = await db
|
62
|
+
.collection("userGroups")
|
63
|
+
.where("groupId", "==", groupID)
|
64
|
+
.get();
|
65
|
+
return snapshot.docs.map((doc) => ({
|
77
66
|
id: doc.id,
|
78
67
|
...doc.data()
|
79
68
|
}));
|
80
69
|
};
|
81
|
-
|
82
|
-
|
83
|
-
const app = initializeApp(firebaseConfig);
|
84
|
-
const db = getFirestore(app);
|
70
|
+
// 7. ADD USER TO GROUP
|
71
|
+
export const addUsersGroup = async (db, groupID, userName, userID) => {
|
85
72
|
const created = new Date().toISOString();
|
86
73
|
const newUserGroup = {
|
87
74
|
user: {
|
@@ -91,19 +78,19 @@ export const addUsersGroup = async (firebaseConfig, groupID, userName, userID) =
|
|
91
78
|
groupId: groupID,
|
92
79
|
created
|
93
80
|
};
|
94
|
-
const docRef = await
|
81
|
+
const docRef = await db.collection("userGroups").add(newUserGroup);
|
95
82
|
return docRef.id;
|
96
83
|
};
|
97
|
-
|
98
|
-
|
99
|
-
const
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
await
|
107
|
-
return
|
84
|
+
// 8. REMOVE USER FROM GROUP
|
85
|
+
export const removeUserGroup = async (db, groupID, userID) => {
|
86
|
+
const snapshot = await db
|
87
|
+
.collection("userGroups")
|
88
|
+
.where("groupId", "==", groupID)
|
89
|
+
.where("user.userId", "==", userID)
|
90
|
+
.get();
|
91
|
+
const doc = snapshot.docs[0];
|
92
|
+
if (doc) {
|
93
|
+
await doc.ref.delete();
|
94
|
+
return doc.id;
|
108
95
|
}
|
109
96
|
};
|