mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-08-25 13:49:40 +00:00
Compare commits
30 Commits
ZBKBCK-54
...
8fb627ec03
Author | SHA1 | Date | |
---|---|---|---|
8fb627ec03 | |||
c3aa31788f | |||
09aecc36b3 | |||
348c5946dd | |||
5603853896 | |||
82b7fe7000 | |||
92679061e2 | |||
67e4e96d85 | |||
df32e5ed37 | |||
e3796f2204 | |||
03f0a4c363 | |||
a3a4a8d091 | |||
772c0c89b5 | |||
d614d13136 | |||
93ce63b1d4 | |||
4f2b42dc08 | |||
5c05a988a5 | |||
2aff4e52f0 | |||
bdc92163c3 | |||
9abf549ed4 | |||
057c58b709 | |||
b1d8949b08 | |||
801bc45bc5 | |||
012d93f70f | |||
652fe9e680 | |||
bf5453c7b7 | |||
47a00f313a | |||
8050e70cf7 | |||
f1333491e0 | |||
4c34c2496b |
@ -216,6 +216,7 @@ class GuardianSerializer(serializers.ModelSerializer):
|
||||
last_name = serializers.SerializerMethodField('get_last_name')
|
||||
auth_token = serializers.SerializerMethodField('get_auth_token')
|
||||
refresh_token = serializers.SerializerMethodField('get_refresh_token')
|
||||
sign_up = serializers.SerializerMethodField()
|
||||
|
||||
def get_auth_token(self, obj):
|
||||
refresh = RefreshToken.for_user(obj.user)
|
||||
@ -253,12 +254,16 @@ class GuardianSerializer(serializers.ModelSerializer):
|
||||
"""user last name"""
|
||||
return obj.user.last_name
|
||||
|
||||
def get_sign_up(self, obj):
|
||||
return True if self.context.get('sign_up', '') else False
|
||||
|
||||
class Meta(object):
|
||||
"""Meta info"""
|
||||
model = Guardian
|
||||
fields = ['id', 'auth_token', 'refresh_token', 'email', 'first_name', 'last_name', 'country_code',
|
||||
'phone', 'family_name', 'gender', 'dob', 'referral_code', 'is_active', 'is_deleted',
|
||||
'is_complete_profile', 'passcode', 'image', 'created_at', 'updated_at', 'user_type', 'country_name']
|
||||
'is_complete_profile', 'passcode', 'image', 'created_at', 'updated_at', 'user_type',
|
||||
'country_name', 'sign_up']
|
||||
|
||||
|
||||
class JuniorSerializer(serializers.ModelSerializer):
|
||||
@ -269,6 +274,7 @@ class JuniorSerializer(serializers.ModelSerializer):
|
||||
last_name = serializers.SerializerMethodField('get_last_name')
|
||||
auth_token = serializers.SerializerMethodField('get_auth_token')
|
||||
refresh_token = serializers.SerializerMethodField('get_refresh_token')
|
||||
sign_up = serializers.SerializerMethodField()
|
||||
|
||||
def get_auth_token(self, obj):
|
||||
refresh = RefreshToken.for_user(obj.auth)
|
||||
@ -295,13 +301,16 @@ class JuniorSerializer(serializers.ModelSerializer):
|
||||
def get_last_name(self, obj):
|
||||
return obj.auth.last_name
|
||||
|
||||
def get_sign_up(self, obj):
|
||||
return True if self.context.get('sign_up', '') else False
|
||||
|
||||
class Meta(object):
|
||||
"""Meta info"""
|
||||
model = Junior
|
||||
fields = ['id', 'auth_token', 'refresh_token', 'email', 'first_name', 'last_name', 'country_code',
|
||||
'phone', 'gender', 'dob', 'guardian_code', 'referral_code','is_active', 'is_password_set',
|
||||
'is_complete_profile', 'created_at', 'image', 'updated_at', 'user_type', 'country_name','is_invited',
|
||||
'is_deleted']
|
||||
'is_deleted', 'sign_up']
|
||||
|
||||
class EmailVerificationSerializer(serializers.ModelSerializer):
|
||||
"""Email verification serializer"""
|
||||
@ -378,7 +387,7 @@ class UpdateUserNotificationSerializer(serializers.ModelSerializer):
|
||||
defaults={
|
||||
'push_notification': validated_data.get('push_notification'),
|
||||
'email_notification': validated_data.get('email_notification'),
|
||||
'sms_notification': validated_data.get('sms_notification'),
|
||||
'sms_notification': validated_data.get('sms_notification', False),
|
||||
})
|
||||
return instance
|
||||
|
||||
|
@ -74,7 +74,7 @@ class GoogleLoginMixin(object):
|
||||
user_info = response.json()
|
||||
email = user_info['email']
|
||||
first_name = user_info['given_name']
|
||||
last_name = user_info['family_name']
|
||||
last_name = user_info['family_name'] if 'family_name' in user_info and user_info['family_name'] else user_info['given_name']
|
||||
profile_picture = user_info['picture']
|
||||
except Exception as e:
|
||||
return custom_error_response(str(e), response_status=status.HTTP_400_BAD_REQUEST)
|
||||
@ -129,7 +129,7 @@ class GoogleLoginMixin(object):
|
||||
junior_code=generate_code(JUN, user_obj.id),
|
||||
referral_code=generate_code(ZOD, user_obj.id)
|
||||
)
|
||||
serializer = JuniorSerializer(junior_query)
|
||||
serializer = JuniorSerializer(junior_query, context={'sign_up': True})
|
||||
position = Junior.objects.all().count()
|
||||
JuniorPoints.objects.create(junior=junior_query, position=position)
|
||||
elif str(user_type) == '2':
|
||||
@ -138,7 +138,7 @@ class GoogleLoginMixin(object):
|
||||
guardian_code=generate_code(GRD, user_obj.id),
|
||||
referral_code=generate_code(ZOD, user_obj.id)
|
||||
)
|
||||
serializer = GuardianSerializer(guardian_query)
|
||||
serializer = GuardianSerializer(guardian_query, context={'sign_up': True})
|
||||
else:
|
||||
user_obj.delete()
|
||||
return custom_error_response(
|
||||
@ -220,7 +220,7 @@ class SigninWithApple(views.APIView):
|
||||
signup_method='3',
|
||||
junior_code=generate_code(JUN, user.id),
|
||||
referral_code=generate_code(ZOD, user.id))
|
||||
serializer = JuniorSerializer(junior_query)
|
||||
serializer = JuniorSerializer(junior_query, context={'sign_up': True})
|
||||
position = Junior.objects.all().count()
|
||||
JuniorPoints.objects.create(junior=junior_query, position=position)
|
||||
elif str(user_type) == '2':
|
||||
@ -228,7 +228,7 @@ class SigninWithApple(views.APIView):
|
||||
signup_method='3',
|
||||
guardian_code=generate_code(GRD, user.id),
|
||||
referral_code=generate_code(ZOD, user.id))
|
||||
serializer = GuardianSerializer(guardian_query)
|
||||
serializer = GuardianSerializer(guardian_query, context={'sign_up': True})
|
||||
else:
|
||||
user.delete()
|
||||
return custom_error_response(
|
||||
@ -760,7 +760,7 @@ class ForceUpdateViewSet(GenericViewSet, mixins.CreateModelMixin):
|
||||
:param kwargs:
|
||||
:return: success message
|
||||
"""
|
||||
if ForceUpdate.objects.all().count() >= 2:
|
||||
if ForceUpdate.objects.all().count() >= 4:
|
||||
return custom_error_response(ERROR_CODE['2080'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
obj_data = [ForceUpdate(**item) for item in request.data]
|
||||
try:
|
||||
|
@ -96,8 +96,8 @@ ERROR_CODE = {
|
||||
"2067": "Action not allowed. User type missing.",
|
||||
"2068": "No guardian associated with this junior",
|
||||
"2069": "Invalid user type",
|
||||
"2070": "You do not find as a guardian",
|
||||
"2071": "You do not find as a junior",
|
||||
"2070": "You are not registered as a guardian in our system. Please try again as junior.",
|
||||
"2071": "You are not registered as a junior in our system. Please try again as guardian.",
|
||||
"2072": "You can not approve or reject this task because junior does not exist in the system",
|
||||
"2073": "You can not approve or reject this junior because junior does not exist in the system",
|
||||
"2074": "You can not complete this task because you does not exist in the system",
|
||||
|
112
fixtures/faq.json
Normal file
112
fixtures/faq.json
Normal file
@ -0,0 +1,112 @@
|
||||
[
|
||||
{
|
||||
"model": "junior.faq",
|
||||
"pk": 1,
|
||||
"fields": {
|
||||
"question": "What is ZOD ?",
|
||||
"description": "We are a future neobank for under 18. We aim to provide children with the ability to use debit cards under the watchfull eye of their parents.",
|
||||
"status": 1,
|
||||
"created_at": "2023-11-08T12:32:55.291Z",
|
||||
"updated_at": "2023-11-08T12:32:55.291Z"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "junior.faq",
|
||||
"pk": 2,
|
||||
"fields": {
|
||||
"question": "What is financial literacy ?",
|
||||
"description": "",
|
||||
"status": 2,
|
||||
"created_at": "2023-11-08T12:32:55.291Z",
|
||||
"updated_at": "2023-11-08T12:32:55.291Z"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "junior.faq",
|
||||
"pk": 3,
|
||||
"fields": {
|
||||
"question": "How can we win with Zod ?",
|
||||
"description": "",
|
||||
"status": 2,
|
||||
"created_at": "2023-11-08T12:32:55.291Z",
|
||||
"updated_at": "2023-11-08T12:32:55.291Z"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "junior.faq",
|
||||
"pk": 4,
|
||||
"fields": {
|
||||
"question": "What is a budget ?",
|
||||
"description": "",
|
||||
"status": 2,
|
||||
"created_at": "2023-11-08T12:32:55.291Z",
|
||||
"updated_at": "2023-11-08T12:32:55.291Z"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "junior.faq",
|
||||
"pk": 5,
|
||||
"fields": {
|
||||
"question": "What is the difference between stocks and bonds ?",
|
||||
"description": "",
|
||||
"status": 2,
|
||||
"created_at": "2023-11-08T12:32:55.291Z",
|
||||
"updated_at": "2023-11-08T12:32:55.291Z"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "junior.faq",
|
||||
"pk": 6,
|
||||
"fields": {
|
||||
"question": "What is compound interest ?",
|
||||
"description": "",
|
||||
"status": 2,
|
||||
"created_at": "2023-11-08T12:32:55.291Z",
|
||||
"updated_at": "2023-11-08T12:32:55.291Z"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "junior.faq",
|
||||
"pk": 7,
|
||||
"fields": {
|
||||
"question": "What is diversification ?",
|
||||
"description": "",
|
||||
"status": 2,
|
||||
"created_at": "2023-11-08T12:32:55.291Z",
|
||||
"updated_at": "2023-11-08T12:32:55.291Z"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "junior.faq",
|
||||
"pk": 8,
|
||||
"fields": {
|
||||
"question": "What is a 401(k) ?",
|
||||
"description": "",
|
||||
"status": 2,
|
||||
"created_at": "2023-11-08T12:32:55.291Z",
|
||||
"updated_at": "2023-11-08T12:32:55.291Z"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "junior.faq",
|
||||
"pk": 9,
|
||||
"fields": {
|
||||
"question": "What is an emergency fund ?",
|
||||
"description": "",
|
||||
"status": 2,
|
||||
"created_at": "2023-11-08T12:32:55.291Z",
|
||||
"updated_at": "2023-11-08T12:32:55.291Z"
|
||||
}
|
||||
},
|
||||
{
|
||||
"model": "junior.faq",
|
||||
"pk": 10,
|
||||
"fields": {
|
||||
"question": "What is a mortgage ?",
|
||||
"description": "",
|
||||
"status": 2,
|
||||
"created_at": "2023-11-08T12:32:55.291Z",
|
||||
"updated_at": "2023-11-08T12:32:55.291Z"
|
||||
}
|
||||
}
|
||||
]
|
@ -19,6 +19,7 @@ from base.pagination import CustomPageNumberPagination
|
||||
"""Django app import"""
|
||||
from drf_yasg.utils import swagger_auto_schema
|
||||
from drf_yasg import openapi
|
||||
from django.core.management import call_command
|
||||
from drf_yasg.views import get_schema_view
|
||||
# Import guardian's model,
|
||||
# Import junior's model,
|
||||
@ -813,7 +814,7 @@ class FAQViewSet(GenericViewSet, mixins.CreateModelMixin,
|
||||
http_method_names = ['get', 'post']
|
||||
|
||||
def get_queryset(self):
|
||||
return FAQ.objects.all()
|
||||
return FAQ.objects.filter(status=1).order_by('id')
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
"""
|
||||
@ -823,6 +824,10 @@ class FAQViewSet(GenericViewSet, mixins.CreateModelMixin,
|
||||
:param kwargs:
|
||||
:return: success message
|
||||
"""
|
||||
load_fixture = request.query_params.get('load_fixture')
|
||||
if load_fixture:
|
||||
call_command('loaddata', 'fixtures/faq.json')
|
||||
return custom_response(SUCCESS_CODE["3045"], response_status=status.HTTP_200_OK)
|
||||
obj_data = [FAQ(**item) for item in request.data]
|
||||
try:
|
||||
FAQ.objects.bulk_create(obj_data)
|
||||
|
@ -56,7 +56,14 @@ if ENV in ['dev', 'qa', 'stage']:
|
||||
# Add more trusted origins as needed
|
||||
]
|
||||
if ENV == "prod":
|
||||
CORS_ALLOWED_ORIGINS = []
|
||||
CORS_ALLOWED_ORIGINS = [
|
||||
# backend base url
|
||||
"https://prod-api.zodbank.com",
|
||||
|
||||
# frontend url
|
||||
"https://web.zodbank.com",
|
||||
# Add more trusted origins as needed
|
||||
]
|
||||
|
||||
# allow all host
|
||||
ALLOWED_HOSTS = ['*']
|
||||
@ -138,9 +145,10 @@ REST_FRAMEWORK = {
|
||||
# define jwt token
|
||||
SIMPLE_JWT = {
|
||||
'ACCESS_TOKEN_LIFETIME': timedelta(hours=2, minutes=59, seconds=59, microseconds=999999),
|
||||
'REFRESH_TOKEN_LIFETIME': timedelta(hours=71, minutes=59, seconds=59, microseconds=999999),
|
||||
'REFRESH_TOKEN_LIFETIME': timedelta(days=364, hours=23, minutes=59, seconds=59, microseconds=999999),
|
||||
|
||||
}
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
|
||||
DATABASES = {
|
||||
@ -200,7 +208,7 @@ AUTH_PASSWORD_VALIDATORS = [
|
||||
# database query logs settings
|
||||
# Allows us to check db hits
|
||||
# useful to optimize db query and hit
|
||||
LOGGING = {
|
||||
LOGGING1 = {
|
||||
"version": 1,
|
||||
"filters": {
|
||||
"require_debug_true": {
|
||||
|
Reference in New Issue
Block a user