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 0dfc2a27
authored
2024-04-05 12:21:03 +0530
by
jaymehta
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
changes
1 parent
a8ec86de
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
146 additions
and
23 deletions
src/api/experience/content-types/experience/schema.json
src/api/experience/controllers/experience.js
src/api/master-day/content-types/master-day/schema.json
src/api/master-month/content-types/master-month/schema.json
src/api/sub-categorie/content-types/sub-categorie/schema.json
src/api/time-slot/content-types/time-slot/schema.json
src/api/experience/content-types/experience/schema.json
View file @
0dfc2a2
...
...
@@ -24,16 +24,6 @@
"address"
:
{
"type"
:
"text"
},
"masterCity"
:
{
"type"
:
"relation"
,
"relation"
:
"oneToOne"
,
"target"
:
"api::master-city.master-city"
},
"masterMonths"
:
{
"type"
:
"relation"
,
"relation"
:
"oneToMany"
,
"target"
:
"api::master-month.master-month"
},
"duration"
:
{
"type"
:
"string"
},
...
...
@@ -58,9 +48,6 @@
"maxGroupSize"
:
{
"type"
:
"string"
},
"indoor"
:
{
"type"
:
"boolean"
},
"subCategory"
:
{
"type"
:
"relation"
,
"relation"
:
"oneToOne"
,
...
...
@@ -90,6 +77,27 @@
"relation"
:
"oneToMany"
,
"target"
:
"api::time-slot.time-slot"
,
"mappedBy"
:
"experience"
},
"masterMonths"
:
{
"type"
:
"relation"
,
"relation"
:
"oneToMany"
,
"target"
:
"api::master-month.master-month"
},
"masterPincode"
:
{
"type"
:
"relation"
,
"relation"
:
"oneToOne"
,
"target"
:
"api::master-pincode.master-pincode"
},
"activityType"
:
{
"type"
:
"enumeration"
,
"enum"
:
[
"indoor"
,
"outdoor"
,
"both"
]
},
"giftSomeone"
:
{
"type"
:
"boolean"
}
}
}
src/api/experience/controllers/experience.js
View file @
0dfc2a2
'use strict'
;
"use strict"
;
const
utils
=
require
(
"@strapi/utils"
);
const
{
ApplicationError
,
ValidationError
}
=
utils
.
errors
;
/**
* experience controller
*/
const
{
createCoreController
}
=
require
(
'@strapi/strapi'
).
factories
;
const
{
createCoreController
}
=
require
(
"@strapi/strapi"
).
factories
;
module
.
exports
=
createCoreController
(
"api::experience.experience"
,
()
=>
({
async
create
(
ctx
)
{
// Validations
if
(
!
ctx
.
request
.
body
.
data
.
vendor
)
{
throw
new
ValidationError
(
"Vendor is a mandatory field."
);
}
if
(
!
ctx
.
request
.
body
.
data
.
pincode
)
{
throw
new
ValidationError
(
"Pincode is a mandatory field."
);
}
if
(
!
ctx
.
request
.
body
.
data
.
subCategory
)
{
throw
new
ValidationError
(
"Subcategory is a mandatory field"
);
}
const
months
=
ctx
.
request
.
body
.
data
.
months
;
if
(
!
months
||
!
months
.
length
>
0
)
{
throw
new
ValidationError
(
"Months is a required field."
);
}
let
monthsIds
=
[];
for
(
let
index
=
0
;
index
<
months
.
length
;
index
++
)
{
const
element
=
months
[
index
];
const
singleMonth
=
await
strapi
.
query
(
"api::master-month.master-month"
)
.
findOne
({
where
:
{
name
:
element
.
value
,
},
});
// console.log("singleMonth", singleMonth);
monthsIds
=
[...
monthsIds
,
singleMonth
.
id
]
}
const
subCategory
=
await
strapi
.
query
(
"api::sub-categorie.sub-categorie"
).
findOne
({
where
:
{
name
:
{
$eq
:
ctx
.
request
.
body
.
data
.
subCategory
}
}
})
const
repeatedActivities
=
await
strapi
.
query
(
"api::experience.experience"
)
.
findOne
({
where
:
{
$and
:
[
{
name
:
ctx
.
request
.
body
.
data
.
name
},
{
vendor
:
ctx
.
request
.
body
.
data
.
vendor
.
id
},
],
},
});
if
(
repeatedActivities
)
{
throw
new
ValidationError
(
"Activity with the same name already exists, please rename the activity."
);
}
// Create Activity
const
activity
=
await
strapi
.
entityService
.
create
(
"api::experience.experience"
,
{
data
:
{
name
:
ctx
.
request
.
body
.
data
.
name
,
description
:
ctx
.
request
.
body
.
data
.
description
,
pricePerPerson
:
ctx
.
request
.
body
.
data
.
pricePerPerson
,
address
:
ctx
.
request
.
body
.
data
.
address
,
masterPincode
:
ctx
.
request
.
body
.
data
.
pincode
.
id
,
minimumDuration
:
ctx
.
request
.
body
.
data
.
minimumDuration
,
maximumDuration
:
ctx
.
request
.
body
.
data
.
maximumDuration
,
ageLowerLimit
:
ctx
.
request
.
body
.
data
.
ageLowerLimit
,
ageNotes
:
ctx
.
request
.
body
.
data
.
ageNotes
,
phoneNumber
:
ctx
.
request
.
body
.
data
.
phoneNumber
,
minGroupSize
:
ctx
.
request
.
body
.
data
.
minGroupSize
,
maxGroupSize
:
ctx
.
request
.
body
.
data
.
maxGroupSize
,
activityType
:
ctx
.
request
.
body
.
data
.
activityType
,
link
:
ctx
.
request
.
body
.
data
.
link
,
cancellationPolicy
:
ctx
.
request
.
body
.
data
.
cancellationPolicy
,
vendor
:
ctx
.
request
.
body
.
data
.
vendor
.
id
,
subCategory
:
subCategory
.
id
,
masterMonths
:
monthsIds
,
giftSomeone
:
ctx
.
request
.
body
.
data
.
giftSomeone
},
}
);
// [{day: "monday", fromTime: "10:20:00", toTime: "18:30:00"}, {day: "tuesday", fromTime: "09:30:00", toTime: "20:00:00"}]
const
timeSlotsArray
=
ctx
.
request
.
body
.
data
.
timeSlots
;
if
(
!
timeSlotsArray
||
!
timeSlotsArray
.
length
>
0
)
{
throw
new
ValidationError
(
"No time slots given."
);
}
let
timeSlotIds
=
[];
for
(
let
index
=
0
;
index
<
timeSlotsArray
.
length
;
index
++
)
{
const
element
=
timeSlotsArray
[
index
];
const
timeSlotEntry
=
await
strapi
.
entityService
.
create
(
"api::time-slot.time-slot"
,
{
data
:
{
masterDay
:
element
.
day
.
id
,
start
:
element
.
fromTime
,
end
:
element
.
toTime
,
experience
:
activity
.
id
,
},
}
);
timeSlotIds
=
[...
timeSlotIds
,
timeSlotEntry
];
}
module
.
exports
=
createCoreController
(
'api::experience.experience'
);
ctx
.
send
({
success
:
true
,
message
:
"Activity Created"
,
data
:
{
...
activity
,
timeSlots
:
{
...
timeSlotIds
}
},
});
},
}));
src/api/master-day/content-types/master-day/schema.json
View file @
0dfc2a2
...
...
@@ -4,10 +4,11 @@
"info"
:
{
"singularName"
:
"master-day"
,
"pluralName"
:
"master-days"
,
"displayName"
:
"Master-days"
"displayName"
:
"Master-days"
,
"description"
:
""
},
"options"
:
{
"draftAndPublish"
:
tru
e
"draftAndPublish"
:
fals
e
},
"pluginOptions"
:
{},
"attributes"
:
{
...
...
src/api/master-month/content-types/master-month/schema.json
View file @
0dfc2a2
...
...
@@ -4,10 +4,11 @@
"info"
:
{
"singularName"
:
"master-month"
,
"pluralName"
:
"master-months"
,
"displayName"
:
"Master-months"
"displayName"
:
"Master-months"
,
"description"
:
""
},
"options"
:
{
"draftAndPublish"
:
tru
e
"draftAndPublish"
:
fals
e
},
"pluginOptions"
:
{},
"attributes"
:
{
...
...
src/api/sub-categorie/content-types/sub-categorie/schema.json
View file @
0dfc2a2
...
...
@@ -25,7 +25,7 @@
"type"
:
"relation"
,
"relation"
:
"oneToOne"
,
"target"
:
"api::experience.experience"
,
"
invers
edBy"
:
"subCategory"
"
mapp
edBy"
:
"subCategory"
}
}
}
src/api/time-slot/content-types/time-slot/schema.json
View file @
0dfc2a2
...
...
@@ -8,7 +8,7 @@
"description"
:
""
},
"options"
:
{
"draftAndPublish"
:
tru
e
"draftAndPublish"
:
fals
e
},
"pluginOptions"
:
{},
"attributes"
:
{
...
...
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