@iservice365/layer-common 0.1.0 → 0.2.1
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/.playground/app.vue +7 -2
- package/.playground/pages/feedback.vue +30 -0
- package/CHANGELOG.md +12 -0
- package/components/Chat/Bubbles.vue +53 -0
- package/components/Chat/Information.vue +187 -0
- package/components/Chat/ListCard.vue +62 -0
- package/components/Chat/Message.vue +149 -0
- package/components/Chat/Navigation.vue +150 -0
- package/components/ConfirmDialog.vue +66 -0
- package/components/Container/Standard.vue +33 -0
- package/components/Feedback/Form.vue +136 -0
- package/components/FeedbackDetail.vue +465 -0
- package/components/FeedbackMain.vue +454 -0
- package/components/FormDialog.vue +65 -0
- package/components/Input/File.vue +203 -0
- package/components/Input/ListGroupSelection.vue +96 -0
- package/components/Input/NewDate.vue +123 -0
- package/components/Input/Number.vue +124 -0
- package/components/InvitationMain.vue +284 -0
- package/components/Layout/Header.vue +14 -4
- package/components/ListView.vue +87 -0
- package/components/MemberMain.vue +459 -0
- package/components/RolePermissionFormCreate.vue +161 -0
- package/components/RolePermissionFormPreviewUpdate.vue +183 -0
- package/components/RolePermissionMain.vue +361 -0
- package/components/ServiceProviderFormCreate.vue +154 -0
- package/components/ServiceProviderMain.vue +195 -0
- package/components/SignaturePad.vue +73 -0
- package/components/SpecificAttr.vue +53 -0
- package/components/SwitchContext.vue +26 -5
- package/components/TableList.vue +150 -0
- package/components/TableListSecondary.vue +164 -0
- package/components/WorkOrder/Create.vue +197 -0
- package/components/WorkOrder/ListView.vue +96 -0
- package/components/WorkOrder/Main.vue +308 -0
- package/components/Workorder.vue +1 -0
- package/composables/useAddress.ts +107 -0
- package/composables/useCommonPermission.ts +130 -0
- package/composables/useCustomer.ts +113 -0
- package/composables/useFeedback.ts +117 -0
- package/composables/useFile.ts +40 -0
- package/composables/useInvoice.ts +18 -0
- package/composables/useLocal.ts +24 -4
- package/composables/useLocalAuth.ts +62 -20
- package/composables/useLocalSetup.ts +13 -0
- package/composables/useMember.ts +111 -0
- package/composables/useOrg.ts +76 -92
- package/composables/usePaymentMethod.ts +101 -0
- package/composables/usePrice.ts +15 -0
- package/composables/usePromoCode.ts +36 -0
- package/composables/useRole.ts +38 -7
- package/composables/useServiceProvider.ts +218 -0
- package/composables/useSite.ts +108 -0
- package/composables/useSubscription.ts +149 -0
- package/composables/useUser.ts +38 -14
- package/composables/useUtils.ts +218 -6
- package/composables/useVerification.ts +33 -0
- package/composables/useWorkOrder.ts +68 -0
- package/middleware/01.auth.ts +11 -0
- package/middleware/02.org.ts +18 -0
- package/middleware/03.customer.ts +13 -0
- package/middleware/member.ts +4 -0
- package/nuxt.config.ts +3 -1
- package/package.json +7 -3
- package/pages/index.vue +3 -0
- package/pages/payment-method-linked.vue +31 -0
- package/pages/require-customer.vue +56 -0
- package/pages/require-organization-membership.vue +47 -0
- package/pages/unauthorized.vue +29 -0
- package/plugins/API.ts +2 -25
- package/plugins/iconify.client.ts +5 -0
- package/plugins/secure-member.client.ts +54 -0
- package/plugins/vuetify.ts +2 -0
- package/public/bg-camera.jpg +0 -0
- package/public/bg-city.jpg +0 -0
- package/public/bg-condo.jpg +0 -0
- package/public/images/icons/delete-icon.png +0 -0
- package/public/sprite.svg +1 -0
- package/types/address.d.ts +13 -0
- package/types/customer.d.ts +15 -0
- package/types/feedback.d.ts +63 -0
- package/types/local.d.ts +47 -38
- package/types/member.d.ts +21 -0
- package/types/org.d.ts +13 -0
- package/types/permission.d.ts +1 -0
- package/types/price.d.ts +17 -0
- package/types/promo-code.d.ts +19 -0
- package/types/service-provider.d.ts +15 -0
- package/types/site.d.ts +13 -0
- package/types/subscription.d.ts +23 -0
- package/types/user.d.ts +19 -0
- package/types/verification.d.ts +20 -0
- package/types/work-order.d.ts +40 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
export function useCommonPermissions() {
|
|
2
|
+
const invitationPermissions: Record<string, TPermission> = {
|
|
3
|
+
"create-invitation": {
|
|
4
|
+
check: true,
|
|
5
|
+
description:
|
|
6
|
+
"Allows the user to create a new invitation for a invitation to join the organization.",
|
|
7
|
+
},
|
|
8
|
+
"view-invitations": {
|
|
9
|
+
check: true,
|
|
10
|
+
description:
|
|
11
|
+
"Allows the user to view the list of all invitation in the organization.",
|
|
12
|
+
},
|
|
13
|
+
"cancel-invitation": {
|
|
14
|
+
check: true,
|
|
15
|
+
description:
|
|
16
|
+
"Allows the user to permanently remove a invitation from the organization.",
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const memberPermissions: Record<string, TPermission> = {
|
|
21
|
+
"view-members": {
|
|
22
|
+
check: true,
|
|
23
|
+
description:
|
|
24
|
+
"Allows the user to view the list of all members in the organization.",
|
|
25
|
+
},
|
|
26
|
+
"assign-member-role": {
|
|
27
|
+
check: true,
|
|
28
|
+
description:
|
|
29
|
+
"Allows the user to assign a specific role to a member in the organization.",
|
|
30
|
+
},
|
|
31
|
+
"suspend-member": {
|
|
32
|
+
check: true,
|
|
33
|
+
description: "Allows the user to suspend a member's account temporarily.",
|
|
34
|
+
},
|
|
35
|
+
"activate-member": {
|
|
36
|
+
check: true,
|
|
37
|
+
description:
|
|
38
|
+
"Allows the user to reactivate a suspended member's account.",
|
|
39
|
+
},
|
|
40
|
+
"delete-member": {
|
|
41
|
+
check: true,
|
|
42
|
+
description:
|
|
43
|
+
"Allows the user to permanently remove a member from the organization.",
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const rolePermissions: Record<string, TPermission> = {
|
|
48
|
+
"add-role": {
|
|
49
|
+
check: true,
|
|
50
|
+
description: "Allows the user to add a new role to the system.",
|
|
51
|
+
},
|
|
52
|
+
"see-all-roles": {
|
|
53
|
+
check: true,
|
|
54
|
+
description: "Allows the user to view the list of all roles.",
|
|
55
|
+
},
|
|
56
|
+
"see-role-details": {
|
|
57
|
+
check: true,
|
|
58
|
+
description: "Allows the user to view the details of a specific role.",
|
|
59
|
+
},
|
|
60
|
+
"delete-role": {
|
|
61
|
+
check: true,
|
|
62
|
+
description:
|
|
63
|
+
"Allows the user to remove a role from the system permanently.",
|
|
64
|
+
},
|
|
65
|
+
"update-role": {
|
|
66
|
+
check: true,
|
|
67
|
+
description: "Allows the user to update the details of an existing role.",
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const feedbackPermissions: Record<string, TPermission> = {
|
|
72
|
+
"add-feedback": {
|
|
73
|
+
check: true,
|
|
74
|
+
description: "Allows the user to create a new feedback.",
|
|
75
|
+
},
|
|
76
|
+
"see-all-feedback": {
|
|
77
|
+
check: true,
|
|
78
|
+
description: "Allows the user to view the list of all feedback.",
|
|
79
|
+
},
|
|
80
|
+
"see-feedback-details": {
|
|
81
|
+
check: true,
|
|
82
|
+
description:
|
|
83
|
+
"Allows the user to view the details of a specific feedback.",
|
|
84
|
+
},
|
|
85
|
+
"delete-feedback": {
|
|
86
|
+
check: true,
|
|
87
|
+
description:
|
|
88
|
+
"Allows the user to remove a feedback from the system permanently.",
|
|
89
|
+
},
|
|
90
|
+
"update-feedback": {
|
|
91
|
+
check: true,
|
|
92
|
+
description:
|
|
93
|
+
"Allows the user to update the details of an existing feedback.",
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const workOrderPermissions: Record<string, TPermission> = {
|
|
98
|
+
"create-work-order": {
|
|
99
|
+
check: true,
|
|
100
|
+
description: "Allows the user to create a new work order.",
|
|
101
|
+
},
|
|
102
|
+
"see-all-work-orders": {
|
|
103
|
+
check: true,
|
|
104
|
+
description: "Allows the user to view the list of all work orders.",
|
|
105
|
+
},
|
|
106
|
+
"see-work-order-details": {
|
|
107
|
+
check: true,
|
|
108
|
+
description:
|
|
109
|
+
"Allows the user to view the details of a specific work order.",
|
|
110
|
+
},
|
|
111
|
+
"delete-work-order": {
|
|
112
|
+
check: true,
|
|
113
|
+
description:
|
|
114
|
+
"Allows the user to remove a work order from the system permanently.",
|
|
115
|
+
},
|
|
116
|
+
"update-work-order": {
|
|
117
|
+
check: true,
|
|
118
|
+
description:
|
|
119
|
+
"Allows the user to update the details of an existing work order.",
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
invitationPermissions,
|
|
125
|
+
memberPermissions,
|
|
126
|
+
rolePermissions,
|
|
127
|
+
feedbackPermissions,
|
|
128
|
+
workOrderPermissions,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
export default function useCustomer() {
|
|
2
|
+
const customers = ref<Array<TCustomer>>([]);
|
|
3
|
+
const page = ref(1);
|
|
4
|
+
const pages = ref(0);
|
|
5
|
+
const pageRange = ref("-- - -- of --");
|
|
6
|
+
const search = ref("");
|
|
7
|
+
|
|
8
|
+
const customer = useState(
|
|
9
|
+
"customer",
|
|
10
|
+
(): TCustomer => ({
|
|
11
|
+
_id: "",
|
|
12
|
+
name: "",
|
|
13
|
+
orgId: "",
|
|
14
|
+
customerOrgId: "",
|
|
15
|
+
createdAt: "",
|
|
16
|
+
updatedAt: "",
|
|
17
|
+
})
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
async function getCustomers({
|
|
21
|
+
page = 1,
|
|
22
|
+
search = "",
|
|
23
|
+
limit = 10,
|
|
24
|
+
organization,
|
|
25
|
+
status = "active",
|
|
26
|
+
sort = "",
|
|
27
|
+
order = "asc",
|
|
28
|
+
}: {
|
|
29
|
+
page?: number;
|
|
30
|
+
search?: string;
|
|
31
|
+
limit?: number;
|
|
32
|
+
organization?: string;
|
|
33
|
+
status?: string;
|
|
34
|
+
sort?: string;
|
|
35
|
+
order?: string;
|
|
36
|
+
} = {}) {
|
|
37
|
+
const { currentUser } = useLocalAuth();
|
|
38
|
+
|
|
39
|
+
const orgId = organization || currentUser.value?.defaultOrg;
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
const response = await useNuxtApp().$api<TCustomerPaginatedResponse>(
|
|
43
|
+
`/api/customers/organization/${orgId}/status/${status}`,
|
|
44
|
+
{
|
|
45
|
+
method: "GET",
|
|
46
|
+
query: { page, search, limit, sort, order },
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
customers.value = response.items;
|
|
51
|
+
pages.value = response.pages;
|
|
52
|
+
pageRange.value = response.pageRange;
|
|
53
|
+
} catch (err) {
|
|
54
|
+
console.error("Error fetching customers:", err);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function createCustomer(payload: TCustomerCreate) {
|
|
59
|
+
return useNuxtApp().$api<Record<string, any>>(`/api/customers`, {
|
|
60
|
+
method: "POST",
|
|
61
|
+
body: payload,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function deleteCustomer(id: string) {
|
|
66
|
+
return useNuxtApp().$api<Record<string, any>>(`/api/customers/${id}`, {
|
|
67
|
+
method: "DELETE",
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function getCustomerById(id: string) {
|
|
72
|
+
return useNuxtApp().$api<TCustomer>(`/api/customers/${id}`, {
|
|
73
|
+
method: "GET",
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function getAll({
|
|
78
|
+
page = 1,
|
|
79
|
+
search = "",
|
|
80
|
+
limit = 10,
|
|
81
|
+
org = "",
|
|
82
|
+
status = "active",
|
|
83
|
+
sort = "",
|
|
84
|
+
order = "asc",
|
|
85
|
+
}: {
|
|
86
|
+
page?: number;
|
|
87
|
+
search?: string;
|
|
88
|
+
limit?: number;
|
|
89
|
+
org?: string;
|
|
90
|
+
status?: string;
|
|
91
|
+
sort?: string;
|
|
92
|
+
order?: string;
|
|
93
|
+
} = {}) {
|
|
94
|
+
return useNuxtApp().$api<Record<string, any>>("/api/customers", {
|
|
95
|
+
method: "GET",
|
|
96
|
+
query: { page, search, limit, sort, order, status, org },
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
customers,
|
|
102
|
+
customer,
|
|
103
|
+
page,
|
|
104
|
+
pages,
|
|
105
|
+
pageRange,
|
|
106
|
+
search,
|
|
107
|
+
getCustomers,
|
|
108
|
+
deleteCustomer,
|
|
109
|
+
createCustomer,
|
|
110
|
+
getCustomerById,
|
|
111
|
+
getAll,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
export default function useFeedback() {
|
|
2
|
+
const feedbacks = useState<Array<TFeedback>>("feedbacks", () => []);
|
|
3
|
+
const page = useState("page", () => 1);
|
|
4
|
+
const pages = useState("pages", () => 0);
|
|
5
|
+
const pageRange = useState("pageRange", () => "-- - -- of --");
|
|
6
|
+
|
|
7
|
+
const feedback = useState(
|
|
8
|
+
"feedback",
|
|
9
|
+
(): TFeedback => ({
|
|
10
|
+
_id: "",
|
|
11
|
+
attachments: [],
|
|
12
|
+
category: "",
|
|
13
|
+
subject: "",
|
|
14
|
+
location: "",
|
|
15
|
+
description: "",
|
|
16
|
+
createdBy: "",
|
|
17
|
+
createdAt: "",
|
|
18
|
+
updatedAt: "",
|
|
19
|
+
status: "pending",
|
|
20
|
+
metadata: {
|
|
21
|
+
serviceProvider: "",
|
|
22
|
+
assignee: "",
|
|
23
|
+
organization: "",
|
|
24
|
+
site: "",
|
|
25
|
+
name: "",
|
|
26
|
+
signature: "",
|
|
27
|
+
attachments: "",
|
|
28
|
+
completedAt: "",
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
async function getFeedbacks({
|
|
34
|
+
page = 1,
|
|
35
|
+
organization = "",
|
|
36
|
+
site = "",
|
|
37
|
+
status = "to-do",
|
|
38
|
+
search = "",
|
|
39
|
+
limit = 10,
|
|
40
|
+
from = "",
|
|
41
|
+
} = {}) {
|
|
42
|
+
try {
|
|
43
|
+
return useNuxtApp().$api<Record<string, any>>(
|
|
44
|
+
`/api/feedbacks/organization/${organization}/site/${site}/status/${status}`,
|
|
45
|
+
{
|
|
46
|
+
method: "GET",
|
|
47
|
+
query: { page, search, limit, from },
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
} catch (err) {
|
|
51
|
+
console.error("Error fetching feedbacks:", err);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function getFeedbackById(id: string) {
|
|
56
|
+
return useNuxtApp().$api<TFeedback>(`/api/feedbacks/${id}`, {
|
|
57
|
+
method: "GET",
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function createFeedback(payload: TFeedbackCreate) {
|
|
62
|
+
return useNuxtApp().$api<Record<string, any>>("/api/feedbacks", {
|
|
63
|
+
method: "POST",
|
|
64
|
+
body: payload,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function updateFeedback(id: string, payload: TFeedbackUpdate) {
|
|
69
|
+
return useNuxtApp().$api<Record<string, any>>(`/api/feedbacks/${id}`, {
|
|
70
|
+
method: "PUT",
|
|
71
|
+
body: payload,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function deleteFeedback(id: string) {
|
|
76
|
+
return useNuxtApp().$api<Record<string, any>>(`/api/feedbacks/${id}`, {
|
|
77
|
+
method: "DELETE",
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function updateFeedbackServiceProvider(id: string, serviceProvider: string) {
|
|
82
|
+
return useNuxtApp().$api<Record<string, any>>(
|
|
83
|
+
`/api/feedbacks/${id}/service-provider`,
|
|
84
|
+
{
|
|
85
|
+
method: "PATCH",
|
|
86
|
+
body: {
|
|
87
|
+
serviceProvider,
|
|
88
|
+
},
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function updateStatusComplete(id: string, payload: TFeedbackStatusComplete) {
|
|
94
|
+
return useNuxtApp().$api<Record<string, any>>(
|
|
95
|
+
`/api/feedbacks/${id}/status-complete`,
|
|
96
|
+
{
|
|
97
|
+
method: "PUT",
|
|
98
|
+
body: payload,
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
feedbacks,
|
|
105
|
+
feedback,
|
|
106
|
+
page,
|
|
107
|
+
pages,
|
|
108
|
+
pageRange,
|
|
109
|
+
getFeedbacks,
|
|
110
|
+
getFeedbackById,
|
|
111
|
+
createFeedback,
|
|
112
|
+
updateFeedback,
|
|
113
|
+
deleteFeedback,
|
|
114
|
+
updateFeedbackServiceProvider,
|
|
115
|
+
updateStatusComplete,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export default function useFile() {
|
|
2
|
+
const baseUrl =
|
|
3
|
+
"https://seven365-storage.sgp1.cdn.digitaloceanspaces.com/dev";
|
|
4
|
+
|
|
5
|
+
function addFile(file: File | null) {
|
|
6
|
+
if (!file) {
|
|
7
|
+
throw new Error("File not found.");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const formData = new FormData();
|
|
11
|
+
formData.append("file", file);
|
|
12
|
+
|
|
13
|
+
return $fetch<Record<string, any>>(
|
|
14
|
+
"https://storage-api-dev-new-wv7cx.ondigitalocean.app/api/files/upload/v2",
|
|
15
|
+
{
|
|
16
|
+
method: "POST",
|
|
17
|
+
body: formData,
|
|
18
|
+
}
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function getFileUrl(id: string) {
|
|
23
|
+
return `${baseUrl}/${id}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function deleteFile(attachmentId: string) {
|
|
27
|
+
return useNuxtApp().$api<Record<string, any>>(
|
|
28
|
+
`/api/files/${attachmentId}`,
|
|
29
|
+
{
|
|
30
|
+
method: "DELETE",
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
addFile,
|
|
37
|
+
deleteFile,
|
|
38
|
+
getFileUrl,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export default function useInvoice() {
|
|
2
|
+
function getBySubscriptionId({ search = "", id = "", page = 1 } = {}) {
|
|
3
|
+
return useNuxtApp().$api<Record<string, any>>(
|
|
4
|
+
`/api/invoices/subscription/${id}`,
|
|
5
|
+
{
|
|
6
|
+
method: "GET",
|
|
7
|
+
params: {
|
|
8
|
+
search,
|
|
9
|
+
page,
|
|
10
|
+
},
|
|
11
|
+
}
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
getBySubscriptionId,
|
|
17
|
+
};
|
|
18
|
+
}
|
package/composables/useLocal.ts
CHANGED
|
@@ -9,26 +9,46 @@ export default function useLocal() {
|
|
|
9
9
|
|
|
10
10
|
const drawer = useState("drawer", () => true);
|
|
11
11
|
|
|
12
|
-
const {
|
|
12
|
+
const { APP_ACCOUNT, APP_ORG } = appConfig;
|
|
13
13
|
|
|
14
14
|
const apps = computed(() => {
|
|
15
15
|
return [
|
|
16
16
|
{
|
|
17
|
-
title: "
|
|
17
|
+
title: "Account",
|
|
18
18
|
icon: "mdi-account-group",
|
|
19
|
-
link:
|
|
20
|
-
landingPage: "
|
|
19
|
+
link: APP_ACCOUNT as string,
|
|
20
|
+
landingPage: "home",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
title: "Organization",
|
|
24
|
+
icon: "mdi-account-group",
|
|
25
|
+
link: APP_ORG as string,
|
|
26
|
+
landingPage: "/",
|
|
21
27
|
},
|
|
22
28
|
];
|
|
23
29
|
});
|
|
24
30
|
|
|
25
31
|
const headerSearch = useState("headerSearch", () => "");
|
|
26
32
|
|
|
33
|
+
const natureOfBusiness = [
|
|
34
|
+
{
|
|
35
|
+
title: "Property Management Agency",
|
|
36
|
+
value: "property_management_agency",
|
|
37
|
+
},
|
|
38
|
+
{ title: "Security Agency", value: "security_agency" },
|
|
39
|
+
{
|
|
40
|
+
title: "Mechanical and Electrical Services",
|
|
41
|
+
value: "mechanical_electrical_services",
|
|
42
|
+
},
|
|
43
|
+
{ title: "Cleaning Services", value: "cleaning_services" },
|
|
44
|
+
];
|
|
45
|
+
|
|
27
46
|
return {
|
|
28
47
|
cookieConfig,
|
|
29
48
|
getUserFromCookie,
|
|
30
49
|
drawer,
|
|
31
50
|
apps,
|
|
32
51
|
headerSearch,
|
|
52
|
+
natureOfBusiness,
|
|
33
53
|
};
|
|
34
54
|
}
|
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
export default function useLocalAuth() {
|
|
2
2
|
const { cookieConfig } = useRuntimeConfig().public;
|
|
3
3
|
|
|
4
|
+
const currentUser = useState<TUser | null>("currentUser", () => null);
|
|
5
|
+
|
|
6
|
+
function authenticate() {
|
|
7
|
+
// Get access token from cookies
|
|
8
|
+
const accessToken = useCookie("accessToken", cookieConfig).value;
|
|
9
|
+
|
|
10
|
+
if (!accessToken) {
|
|
11
|
+
// Redirect to login page if no access token
|
|
12
|
+
navigateTo({ name: "index" });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const user = useCookie("user", cookieConfig).value;
|
|
16
|
+
|
|
17
|
+
const { data: getCurrentUserReq, error: getCurrentUserErr } =
|
|
18
|
+
useLazyAsyncData("getCurrentUser", () =>
|
|
19
|
+
useNuxtApp().$api<TUser>(`/api/users/id/${user}`)
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
watchEffect(() => {
|
|
23
|
+
if (getCurrentUserReq.value) {
|
|
24
|
+
currentUser.value = getCurrentUserReq.value;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
watchEffect(() => {
|
|
29
|
+
if (getCurrentUserErr.value) {
|
|
30
|
+
// Redirect to login page if user authentication fails
|
|
31
|
+
navigateTo({ name: "index" });
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
4
36
|
async function login({ email = "", password = "" }) {
|
|
5
37
|
return useNuxtApp().$api<Record<string, any>>("/api/auth", {
|
|
6
38
|
method: "POST",
|
|
@@ -8,15 +40,13 @@ export default function useLocalAuth() {
|
|
|
8
40
|
});
|
|
9
41
|
}
|
|
10
42
|
|
|
11
|
-
function
|
|
12
|
-
useCookie("
|
|
13
|
-
useCookie("refreshToken", cookieConfig).value = refreshToken;
|
|
43
|
+
function setSession({ sid = "", user = "" }) {
|
|
44
|
+
useCookie("sid", cookieConfig).value = sid;
|
|
14
45
|
useCookie("user", cookieConfig).value = user;
|
|
15
46
|
}
|
|
16
47
|
|
|
17
48
|
function clearCookies() {
|
|
18
|
-
useCookie("
|
|
19
|
-
useCookie("refreshToken", cookieConfig).value = null;
|
|
49
|
+
useCookie("sid", cookieConfig).value = null;
|
|
20
50
|
useCookie("user", cookieConfig).value = null;
|
|
21
51
|
useCookie("organization", cookieConfig).value = null;
|
|
22
52
|
}
|
|
@@ -36,8 +66,6 @@ export default function useLocalAuth() {
|
|
|
36
66
|
}
|
|
37
67
|
}
|
|
38
68
|
|
|
39
|
-
const currentUser = useState((): TUser | null => null);
|
|
40
|
-
|
|
41
69
|
async function getCurrentUser() {
|
|
42
70
|
const user = useCookie("user", cookieConfig).value;
|
|
43
71
|
if (!user) return null;
|
|
@@ -54,12 +82,14 @@ export default function useLocalAuth() {
|
|
|
54
82
|
}
|
|
55
83
|
|
|
56
84
|
try {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
85
|
+
return await useNuxtApp().$api<Record<string, any>>(
|
|
86
|
+
"/api/auth/forget-password",
|
|
87
|
+
{
|
|
88
|
+
method: "POST",
|
|
89
|
+
body: JSON.stringify({ email }),
|
|
90
|
+
headers: { "Content-Type": "application/json" },
|
|
91
|
+
}
|
|
92
|
+
);
|
|
63
93
|
} catch (error) {
|
|
64
94
|
console.error("Error in password reset request:", error);
|
|
65
95
|
throw error;
|
|
@@ -72,11 +102,14 @@ export default function useLocalAuth() {
|
|
|
72
102
|
passwordConfirmation: string
|
|
73
103
|
) {
|
|
74
104
|
try {
|
|
75
|
-
return await useNuxtApp().$api
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
105
|
+
return await useNuxtApp().$api<Record<string, any>>(
|
|
106
|
+
"/api/auth/reset-password",
|
|
107
|
+
{
|
|
108
|
+
method: "POST",
|
|
109
|
+
body: JSON.stringify({ otp, newPassword, passwordConfirmation }),
|
|
110
|
+
headers: { "Content-Type": "application/json" },
|
|
111
|
+
}
|
|
112
|
+
);
|
|
80
113
|
} catch (error) {
|
|
81
114
|
console.error("Error resetting password:", error);
|
|
82
115
|
throw error;
|
|
@@ -84,20 +117,29 @@ export default function useLocalAuth() {
|
|
|
84
117
|
}
|
|
85
118
|
|
|
86
119
|
function verify(id: string) {
|
|
87
|
-
return useNuxtApp().$api<
|
|
120
|
+
return useNuxtApp().$api<Record<string, any>>(`/api/auth/verify/${id}`, {
|
|
88
121
|
method: "GET",
|
|
89
122
|
});
|
|
90
123
|
}
|
|
91
124
|
|
|
125
|
+
function signUp(email: string, referral: string) {
|
|
126
|
+
return useNuxtApp().$api<Record<string, any>>("/api/auth/sign-up", {
|
|
127
|
+
method: "POST",
|
|
128
|
+
body: { email, referral },
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
92
132
|
return {
|
|
133
|
+
authenticate,
|
|
93
134
|
login,
|
|
135
|
+
setSession,
|
|
94
136
|
logout,
|
|
95
137
|
clearCookies,
|
|
96
138
|
getCurrentUser,
|
|
97
|
-
setToken,
|
|
98
139
|
forgotPassword,
|
|
99
140
|
resetPassword,
|
|
100
141
|
currentUser,
|
|
101
142
|
verify,
|
|
143
|
+
signUp,
|
|
102
144
|
};
|
|
103
145
|
}
|