@solidstarters/solid-core 1.2.13 → 1.2.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidstarters/solid-core",
3
- "version": "1.2.13",
3
+ "version": "1.2.14",
4
4
  "description": "This module is a NestJS module containing all the required core providers required by a Solid application",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,7 +1,7 @@
1
1
  import { BadRequestException } from "@nestjs/common";
2
2
  import { ConfigService } from "@nestjs/config";
3
3
  import { DiscoveryService } from "@nestjs/core";
4
- import { EntityManager, QueryFailedError, SelectQueryBuilder } from "typeorm";
4
+ import { EntityManager, In, IsNull, Not, QueryFailedError, SelectQueryBuilder } from "typeorm";
5
5
  import { Repository } from "typeorm/repository/Repository";
6
6
  import { BasicFilterDto } from "../dtos/basic-filters.dto";
7
7
  import { ComputedFieldValueType, RelationType, SelectionValueType, SolidFieldType } from "../dtos/create-field-metadata.dto";
@@ -649,4 +649,77 @@ export class CRUDService<T> { //Add two generic value i.e Person,CreatePersonDto
649
649
  // return removedEntities
650
650
  }
651
651
 
652
+ async recover(id: number) {
653
+ try {
654
+ const softDeletedRows = await this.repo.findOne({
655
+ where: {
656
+ //@ts-ignore
657
+ id, deletedAt: Not(IsNull())
658
+ },
659
+ withDeleted: true,
660
+ });
661
+
662
+ if (!softDeletedRows) {
663
+ throw new Error('No soft-deleted record found with the given ID.');
664
+ }
665
+
666
+ await this.repo.update(id, {
667
+ //@ts-ignore
668
+ deletedAt: null, deletedTracker: "not-deleted"
669
+ });
670
+
671
+ return { message: 'Record successfully recovered', data: softDeletedRows };
672
+ } catch (error) {
673
+ if (error instanceof QueryFailedError) {
674
+ if ((error as any).code === '23505') {
675
+ throw new Error('Another record is conflicting with the record you are attempting to Un-Archive, either delete or change the other record so as to avoid this conflict.');
676
+ }
677
+ }
678
+
679
+ throw new Error(error);
680
+ }
681
+ }
682
+
683
+ async recoverMany(ids: number[]) {
684
+ try {
685
+ if (!ids || ids.length === 0) {
686
+ throw new Error("No IDs provided for recovery.");
687
+ }
688
+
689
+ // Find soft-deleted records matching the given IDs
690
+ const softDeletedRows = await this.repo.find({
691
+ where: {
692
+ //@ts-ignore
693
+ id: In(ids),
694
+ deletedAt: Not(IsNull()),
695
+ },
696
+ withDeleted: true,
697
+ });
698
+
699
+ if (softDeletedRows.length === 0) {
700
+ throw new Error("No matching soft-deleted records found.");
701
+ }
702
+
703
+ // Recover the specific records by setting deletedAt to null
704
+ await this.repo.update(
705
+ //@ts-ignore
706
+ { id: In(ids) },
707
+ { deletedAt: null, deletedTracker: "not-deleted" }
708
+ );
709
+
710
+ return { message: "Selected records successfully recovered", recoveredIds: ids };
711
+ } catch (error) {
712
+ if (error instanceof QueryFailedError) {
713
+ if ((error as any).code === "23505") {
714
+ throw new Error(
715
+ "Another record is conflicting with the record you are attempting to Un-Archive, either delete or change the other record to avoid this conflict."
716
+ );
717
+ }
718
+ }
719
+
720
+ throw new Error(error);
721
+ }
722
+ }
723
+
724
+
652
725
  }