first
This commit is contained in:
@@ -0,0 +1,238 @@
|
||||
import { Expose, Type } from "class-transformer";
|
||||
import { ArrayMinSize, IsArray, IsNotEmpty, IsOptional, IsString, ValidateNested } from "class-validator";
|
||||
|
||||
import { ApiProperty } from "../../../common/decorator/swggerDocs";
|
||||
|
||||
class downloadAppValue {
|
||||
@Expose()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ApiProperty({ type: "string", description: "picture url", example: "https://google.com" })
|
||||
pic: string;
|
||||
|
||||
@Expose()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ApiProperty({ type: "string", description: "url of download app", example: "https://google.com" })
|
||||
url: string;
|
||||
}
|
||||
|
||||
class socialMediaLinksValue {
|
||||
@Expose()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ApiProperty({ type: "string", description: "icon of Social media", example: "Telegram" })
|
||||
icon: string;
|
||||
|
||||
@Expose()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ApiProperty({ type: "string", description: "url of download app", example: "https://google.com" })
|
||||
url: string;
|
||||
}
|
||||
|
||||
export class CreateSiteSettingDTO {
|
||||
@Expose()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ApiProperty({ type: "string", description: "Site Url", example: "https://google.com" })
|
||||
siteLogo: string;
|
||||
|
||||
@Expose()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ApiProperty({ type: "string", description: "phone of site", example: "09918914108" })
|
||||
footerPhone: string;
|
||||
|
||||
@Expose()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ApiProperty({ type: "string", description: "email of site", example: "matin@gmail.com" })
|
||||
footerEmail: string;
|
||||
|
||||
@Expose()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ApiProperty({ type: "string", description: "address of site", example: "اراک خیابان جنت" })
|
||||
footerAddress: string;
|
||||
|
||||
@Expose()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ApiProperty({
|
||||
type: "string",
|
||||
description: "description of site",
|
||||
example: "لورم ایپسوم متن ساختگی با تولید سادگی نامفهوم از صنعت چاپ، و با استفاده از طراحان گرافیک است،",
|
||||
})
|
||||
footerDescription: string;
|
||||
|
||||
@Expose()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ApiProperty({ type: "string", description: "content of shipment", example: "رویه ارسال سندس کالا" })
|
||||
shipmentContent: string;
|
||||
|
||||
@Expose()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ApiProperty({ type: "string", description: "content of faq", example: "سوالات متداول" })
|
||||
faqContent: string;
|
||||
|
||||
@Expose()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ApiProperty({ type: "string", description: "content of policy", example: "حریم خصوصی" })
|
||||
policyContent: string;
|
||||
|
||||
@Expose()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ApiProperty({ type: "string", description: "content of return rule", example: "رویه ارسال سندس کالا" })
|
||||
returnRulesContent: string;
|
||||
|
||||
@Expose()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ApiProperty({ type: "string", description: "content of jobs", example: "به تیم ما بپیوندید" })
|
||||
jobsContent: string;
|
||||
|
||||
@Expose()
|
||||
@IsNotEmpty()
|
||||
@IsArray()
|
||||
@ArrayMinSize(1)
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => downloadAppValue)
|
||||
@ApiProperty({
|
||||
type: "Array",
|
||||
description: "download app details of site",
|
||||
example: [
|
||||
{ pic: "https://google.com", url: "https://google.com" },
|
||||
{ pic: "https://youtube.com", url: "https://youtube.com" },
|
||||
],
|
||||
})
|
||||
downloadAppDetails: downloadAppValue[];
|
||||
|
||||
@Expose()
|
||||
@IsNotEmpty()
|
||||
@IsArray()
|
||||
@ArrayMinSize(1)
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => socialMediaLinksValue)
|
||||
@ApiProperty({
|
||||
type: "Array",
|
||||
description: "social media details of site",
|
||||
example: [
|
||||
{ icon: "telegram", url: "https://web.telegram.com" },
|
||||
{ icon: "youtube", url: "https://youtube.com/me" },
|
||||
],
|
||||
})
|
||||
socialMediaLinks: socialMediaLinksValue[];
|
||||
}
|
||||
|
||||
export class UpdateSiteSettingDTO {
|
||||
@Expose()
|
||||
@IsOptional()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ApiProperty({ type: "string", description: "Site Url", example: "https://google.com" })
|
||||
siteLogo: string;
|
||||
|
||||
@Expose()
|
||||
@IsOptional()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ApiProperty({ type: "string", description: "phone of site", example: "09918914108" })
|
||||
footerPhone: string;
|
||||
|
||||
@Expose()
|
||||
@IsOptional()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ApiProperty({ type: "string", description: "email of site", example: "matin@gmail.com" })
|
||||
footerEmail: string;
|
||||
|
||||
@Expose()
|
||||
@IsOptional()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ApiProperty({ type: "string", description: "address of site", example: "اراک خیابان جنت" })
|
||||
footerAddress: string;
|
||||
|
||||
@Expose()
|
||||
@IsOptional()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ApiProperty({ type: "string", description: "content of shipment", example: "رویه ارسال سندس کالا" })
|
||||
shipmentContent: string;
|
||||
|
||||
@Expose()
|
||||
@IsOptional()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ApiProperty({ type: "string", description: "content of faq", example: "سوالات متداول" })
|
||||
faqContent: string;
|
||||
|
||||
@Expose()
|
||||
@IsOptional()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ApiProperty({ type: "string", description: "content of policy", example: "حریم خصوصی" })
|
||||
policyContent: string;
|
||||
|
||||
@Expose()
|
||||
@IsOptional()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ApiProperty({ type: "string", description: "content of return rule", example: "رویه ارسال سندس کالا" })
|
||||
returnRulesContent: string;
|
||||
|
||||
@Expose()
|
||||
@IsOptional()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ApiProperty({ type: "string", description: "content of jobs", example: "به تیم ما بپیوندید" })
|
||||
jobsContent: string;
|
||||
|
||||
@Expose()
|
||||
@IsOptional()
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
@ApiProperty({
|
||||
type: "string",
|
||||
description: "description of site",
|
||||
example: "لورم ایپسوم متن ساختگی با تولید سادگی نامفهوم از صنعت چاپ، و با استفاده از طراحان گرافیک است،",
|
||||
})
|
||||
footerDescription: string;
|
||||
|
||||
@Expose()
|
||||
@IsOptional()
|
||||
@IsNotEmpty()
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => downloadAppValue)
|
||||
@ApiProperty({
|
||||
type: "Array",
|
||||
description: "download app details of site",
|
||||
example: [
|
||||
{ pic: "https://google.com", url: "https://google.com" },
|
||||
{ pic: "https://youtube.com", url: "https://youtube.com" },
|
||||
],
|
||||
})
|
||||
downloadAppDetails: downloadAppValue[];
|
||||
|
||||
@Expose()
|
||||
@IsOptional()
|
||||
@IsNotEmpty()
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => socialMediaLinksValue)
|
||||
@ApiProperty({
|
||||
type: "Array",
|
||||
description: "social media details of site",
|
||||
example: [
|
||||
{ icon: "telegram", url: "https://web.telegram.com" },
|
||||
{ icon: "youtube", url: "https://youtube.com/me" },
|
||||
],
|
||||
})
|
||||
socialMediaLinks: socialMediaLinksValue[];
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
export interface ISiteSetting {
|
||||
siteLogo: string;
|
||||
footerDescription: string;
|
||||
footerAddress: string;
|
||||
footerEmail: string;
|
||||
footerPhone: string;
|
||||
downloadAppDetails: [
|
||||
{
|
||||
pic: string;
|
||||
url: string;
|
||||
},
|
||||
];
|
||||
socialMediaLinks: [
|
||||
{
|
||||
icon: string;
|
||||
url: string;
|
||||
},
|
||||
];
|
||||
shipmentContent: string;
|
||||
faqContent: string;
|
||||
policyContent: string;
|
||||
returnRulesContent: string;
|
||||
jobsContent: string;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { Schema, model } from "mongoose";
|
||||
|
||||
import { ISiteSetting } from "./Abstractions/ISiteSetting";
|
||||
|
||||
const SiteSettingSchema = new Schema<ISiteSetting>(
|
||||
{
|
||||
siteLogo: { type: String, required: true },
|
||||
footerDescription: { type: String, required: true },
|
||||
footerAddress: { type: String, required: true },
|
||||
footerEmail: { type: String, required: true },
|
||||
footerPhone: { type: String, required: true },
|
||||
downloadAppDetails: [
|
||||
{
|
||||
pic: { type: String, required: true },
|
||||
url: { type: String, required: true },
|
||||
},
|
||||
],
|
||||
socialMediaLinks: [
|
||||
{
|
||||
icon: { type: String, required: true },
|
||||
url: { type: String, required: true },
|
||||
},
|
||||
],
|
||||
shipmentContent: { type: String, required: true },
|
||||
faqContent: { type: String, required: true },
|
||||
policyContent: { type: String, required: true },
|
||||
returnRulesContent: { type: String, required: true },
|
||||
jobsContent: { type: String, required: true },
|
||||
},
|
||||
{
|
||||
timestamps: true,
|
||||
toJSON: { versionKey: false, virtuals: true },
|
||||
id: false,
|
||||
},
|
||||
);
|
||||
const SiteSettingModel = model<ISiteSetting>("SiteSetting", SiteSettingSchema);
|
||||
|
||||
export { SiteSettingModel };
|
||||
@@ -0,0 +1,26 @@
|
||||
import { inject } from "inversify";
|
||||
import { controller, httpGet, queryParam } from "inversify-express-utils";
|
||||
|
||||
import { SiteSettingService } from "./siteSetting.service";
|
||||
import { HttpStatus } from "../../common";
|
||||
import { BaseController } from "../../common/base/controller";
|
||||
import { ApiOperation, ApiQuery, ApiResponse, ApiTags } from "../../common/decorator/swggerDocs";
|
||||
import { IOCTYPES } from "../../IOC/ioc.types";
|
||||
|
||||
@controller("/site-setting")
|
||||
@ApiTags("Site Setting")
|
||||
export class SiteSettingController extends BaseController {
|
||||
@inject(IOCTYPES.SiteSettingService) siteSettingService: SiteSettingService;
|
||||
|
||||
@ApiOperation("get all Site setting")
|
||||
@ApiResponse("successful", HttpStatus.Ok)
|
||||
@ApiQuery(
|
||||
"name",
|
||||
"the name of setting ==> value siteLogo | footerDescription | footerAddress | footerEmail | footerPhone | downloadAppDetails | socialMediaLinks | shipmentContent | faqContent | policyContent | returnRulesContent | jobsContent",
|
||||
)
|
||||
@httpGet("")
|
||||
public async getSiteSetting(@queryParam("name") name: string) {
|
||||
const data = await this.siteSettingService.getSiteSetting(name);
|
||||
return this.response(data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { ISiteSetting } from "./model/Abstractions/ISiteSetting";
|
||||
import { SiteSettingModel } from "./model/siteSetting.model";
|
||||
import { BaseRepository } from "../../common/base/repository";
|
||||
|
||||
export class SiteSettingRepo extends BaseRepository<ISiteSetting> {
|
||||
constructor() {
|
||||
super(SiteSettingModel);
|
||||
}
|
||||
}
|
||||
|
||||
export function CreateSiteSettingRepo(): SiteSettingRepo {
|
||||
return new SiteSettingRepo();
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { inject, injectable } from "inversify";
|
||||
|
||||
import { CreateSiteSettingDTO, UpdateSiteSettingDTO } from "./DTO/siteSetting.dto";
|
||||
import { SiteSettingRepo } from "./siteSetting.repository";
|
||||
import { CommonMessage } from "../../common/enums/message.enum";
|
||||
import { BadRequestError } from "../../core/app/app.errors";
|
||||
import { IOCTYPES } from "../../IOC/ioc.types";
|
||||
|
||||
@injectable()
|
||||
export class SiteSettingService {
|
||||
@inject(IOCTYPES.SiteSettingRepo) siteSettingRepo: SiteSettingRepo;
|
||||
|
||||
async createSiteSetting(createDto: CreateSiteSettingDTO) {
|
||||
const existSiteSetting = await this.siteSettingRepo.findAll();
|
||||
if (existSiteSetting.length > 0) throw new BadRequestError(CommonMessage.SettingExists);
|
||||
const siteSetting = await this.siteSettingRepo.model.create(createDto);
|
||||
return { siteSetting };
|
||||
}
|
||||
|
||||
async getSiteSetting(name?: string) {
|
||||
const projection = name ? { [name]: 1 } : {};
|
||||
const siteSetting = await this.siteSettingRepo.model.findOne({}, projection);
|
||||
return { siteSetting };
|
||||
}
|
||||
|
||||
async updateSiteSetting(updateDto: UpdateSiteSettingDTO) {
|
||||
const siteSetting = await this.siteSettingRepo.model.findOneAndUpdate({}, updateDto, { new: true });
|
||||
return { siteSetting };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user