예제 #1
0
    async def update(self, catalog_dto: Catalog) -> Union[bool, UpdateResult]:

        self.date_sanitation(SanitationMode.rm_create_date,
                             catalog_dto)  # Update date sanitation
        catalog_dto.updatedAt = datetime.utcnow()

        try:
            q_result: UpdateResult = await self.collection.update_one(
                {'_id': catalog_dto.id},
                {'$set': catalog_dto.dict(by_alias=True, exclude_none=True)})
        except:
            return False

        return q_result
예제 #2
0
    async def create(self,
                     catalog_dto: Catalog) -> Union[bool, InsertOneResult]:
        """
        Created a new catalog in to the database

        :param catalog_dto: The Catalog to be added
        :return: The new added already catalog object
        """

        catalog_dto.createdAt = datetime.utcnow()

        self.id_sanitation(catalog_dto)  # if the dto has id, we remove it
        self.date_sanitation(SanitationMode.rm_update_date,
                             catalog_dto)  # Update date sanitation

        try:
            q_result: InsertOneResult = await self.collection.insert_one(
                catalog_dto.dict(by_alias=True))
        except:
            return False

        return q_result