App Creators Schema

 avatar
NexAI
typescript
18 days ago
3.0 kB
2
Indexable
import { Schema, model } from "mongoose";
import paginate from "mongoose-paginate-v2";
import { IAppSettings, IAppSettingsModel } from "../interfaces";
import AppVersion from "./AppVersion";
import AppAdds from "./AppAdds";

const schema: Schema = new Schema<IAppSettings, IAppSettingsModel>(
  {
    name: {
      type: String,
      required: [true, "Name is required"],
      trim: true,
    },
    appId: {
      type: String,
      required: [true, "App ID is required"],
      trim: true,
    },
    platform: {
      type: String,
      enum: ["android", "ios"],
      required: [true, "Platform is required"],
    },
    appType: {
      type: String,
      enum: ["cricket", "football"],
      required: [true, "App Type is required"],
    },
    logo: {
      type: String,
      default: ""
    },
    topic: {
      type: String,
      default: '',
      trim: true,
    },
    firebaseJSON: {
      type: Object,
      default: {},
    },
    status: {
      type: String,
      enum: ["live", "under-development", "in-review", "app-rejected", "store-issue"],
      required: [true, "Status is required"],
    },
    privacyPolicy: {
      type: String,
      default: ""
    },
    termsAndConditions: {
      type: String,
      default: ""
    },
    link: {
      type: String,
      default: "",
      trim: true,
    },
    defaultPage: {
      type: String,
      default: "",
      trim: true,
    },
    versionCode: {
      type: String,
      default: "",
    },
    forceUpdate: {
      type: Object,
      default: {
        updateVersionCode: "",
        forceUpdate: "off",
        forceUpdateAppUrl: "",
        forceUpdateButtonText: "",
        forceUpdateDescription: ""
      },
    },
    promotion: {
      type: Object,
      default: {
        status: "off",
        buttonName: "",
        text: "",
        url: ""
      },
    },
    donation: {
      type: Object,
      default: {
        status: "off",
        buttonName: "",
        text: "",
        url: ""
      },
    },
    social: {
      type: Object,
      default: {
        facebook: "",
        telegram: "",
        youtube: "",
        tiktok: "",
        instagram: "",
        twitter: "",
        whatsapp: "",
        email: "",
        discord: "",
      }
    },
    versionsControl: [{
      type: Schema.Types.ObjectId,
      ref: "AppVersion",
    }],
    adds: [{
      type: Schema.Types.ObjectId,
      ref: "AppAdds",
    }]
  },
  {
    timestamps: true,
  }
);

schema.plugin(paginate);
schema.methods.toJSON = function () {
  const obj = this.toObject();
  delete obj.__v;
  return JSON.parse(JSON.stringify(obj).replace(/_id/g, "id"));
};

schema.post("findOneAndDelete", async (doc, next) => {
  try {
    await AppVersion.deleteMany({ app: doc._id });
    await AppAdds.deleteMany({ app: doc._id });
    next();
  } catch (err) {
    console.error(err);
    next();
  }
});

const AppSettings = model<IAppSettings, IAppSettingsModel>(
  "AppSetting",
  schema,
  "appSettings"
);

export default AppSettings;
Editor is loading...
Leave a Comment