mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-17 02:45:08 +00:00
notification app, api for device registration and fcm token
This commit is contained in:
28
notifications/serializers.py
Normal file
28
notifications/serializers.py
Normal file
@ -0,0 +1,28 @@
|
||||
"""
|
||||
notification serializer file
|
||||
"""
|
||||
# third party imports
|
||||
from rest_framework import serializers
|
||||
|
||||
# local imports
|
||||
from notifications.utils import register_fcm_token
|
||||
|
||||
|
||||
class RegisterDevice(serializers.Serializer):
|
||||
"""
|
||||
used to create and validate register device token
|
||||
"""
|
||||
registration_id = serializers.CharField(max_length=250)
|
||||
device_id = serializers.CharField(max_length=250)
|
||||
type = serializers.ChoiceField(choices=["ios", "web", "android"])
|
||||
|
||||
class Meta:
|
||||
""" meta class """
|
||||
fields = ('registration_id', 'type', 'device_id')
|
||||
|
||||
def create(self, validated_data):
|
||||
""" override this method to create device token for users """
|
||||
registration_id = validated_data['registration_id']
|
||||
device_type = validated_data['type']
|
||||
return register_fcm_token(self.context['user_id'], registration_id,
|
||||
validated_data['device_id'], device_type)
|
Reference in New Issue
Block a user