Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Jay Mehta
/
zango-strapi
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Registry
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit abd3bfef
authored
2024-03-06 15:09:40 +0530
by
jay
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
OTP, vendor and user APIs ready
1 parent
36d44755
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
3 deletions
src/api/vendor/content-types/vendor/schema.json
src/api/vendor/controllers/vendor.js
src/extensions/users-permissions/content-types/user/schema.json
src/extensions/users-permissions/strapi-server.js
src/api/vendor/content-types/vendor/schema.json
View file @
abd3bfe
...
@@ -20,6 +20,15 @@
...
@@ -20,6 +20,15 @@
"relation"
:
"oneToMany"
,
"relation"
:
"oneToMany"
,
"target"
:
"api::experience.experience"
,
"target"
:
"api::experience.experience"
,
"mappedBy"
:
"vendor"
"mappedBy"
:
"vendor"
},
"email"
:
{
"type"
:
"string"
},
"user"
:
{
"type"
:
"relation"
,
"relation"
:
"oneToOne"
,
"target"
:
"plugin::users-permissions.user"
,
"inversedBy"
:
"vendor"
}
}
}
}
}
}
src/api/vendor/controllers/vendor.js
View file @
abd3bfe
'use strict'
;
"use strict"
;
/**
/**
* vendor controller
* vendor controller
*/
*/
const
{
createCoreController
}
=
require
(
'@strapi/strapi'
).
factories
;
const
{
createCoreController
}
=
require
(
"@strapi/strapi"
).
factories
;
module
.
exports
=
createCoreController
(
'api::vendor.vendor'
);
module
.
exports
=
createCoreController
(
"api::vendor.vendor"
,
()
=>
({
async
create
(
ctx
)
{
// console.log("ctx", ctx.request.body);
// Get user from user entity
const
currentUser
=
await
strapi
.
query
(
"plugin::users-permissions.user"
)
.
findOne
({
populate
:
[
"user"
],
where
:
{
$and
:
[{
email
:
ctx
.
request
.
body
.
data
.
email
}],
},
});
// Check if its already existing in vendor entity
// console.log("currentUser", currentUser);
let
existingUser
;
existingUser
=
await
strapi
.
entityService
.
findMany
(
"api::vendor.vendor"
,
{
fields
:
[
"id"
],
filter
:
{
phoneNumber
:
ctx
.
request
.
body
.
data
.
phoneNumber
},
});
if
(
!
existingUser
)
{
existingUser
=
await
strapi
.
entityService
.
findMany
(
"api::vendor.vendor"
,
{
fields
:
[
"id"
],
filters
:
{
email
:
ctx
.
request
.
body
.
data
.
email
},
});
}
// Generate one time password (otp)
const
oneTimePassword
=
Math
.
floor
(
100000
+
Math
.
random
()
*
900000
);
await
strapi
.
entityService
.
update
(
"plugin::users-permissions.user"
,
currentUser
.
id
,
{
data
:
{
oneTimePassword
:
`
${
oneTimePassword
}
`
,
},
}
);
const
date
=
new
Date
();
// TODO: Code to send OTP on email
// TODO: Code to send OTP on SMS
if
(
existingUser
&&
existingUser
.
length
!==
0
)
{
}
else
{
ctx
.
request
.
body
.
data
.
user
=
currentUser
.
id
;
const
response
=
await
strapi
.
entityService
.
create
(
"api::vendor.vendor"
,
{
data
:
{
...
ctx
.
request
.
body
.
data
,
publishedAt
:
date
},
});
console
.
log
(
"response"
,
response
);
return
{
otpSent
:
true
,
data
:
response
};
// ctx.request.body.data.user = currentUser;
// console.log("ctx.request.body.data", ctx.request.body.data);
// return await super.create(ctx);
}
ctx
.
send
({
ok
:
true
,
message
:
"Existing vendor found, skipping creation only sent OTP."
,
});
},
}));
src/extensions/users-permissions/content-types/user/schema.json
View file @
abd3bfe
...
@@ -70,6 +70,12 @@
...
@@ -70,6 +70,12 @@
},
},
"dialCode"
:
{
"dialCode"
:
{
"type"
:
"string"
"type"
:
"string"
},
"vendor"
:
{
"type"
:
"relation"
,
"relation"
:
"oneToOne"
,
"target"
:
"api::vendor.vendor"
,
"inversedBy"
:
"user"
}
}
}
}
}
}
src/extensions/users-permissions/strapi-server.js
View file @
abd3bfe
This diff is collapsed.
Click to expand it.
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment