debugging and add image uploader to guild good
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
|||||||
PartnerStatus,
|
PartnerStatus,
|
||||||
} from '@/generated/prisma/enums'
|
} from '@/generated/prisma/enums'
|
||||||
import { ConsumerCreateInput, ConsumerSelect } from '@/generated/prisma/models'
|
import { ConsumerCreateInput, ConsumerSelect } from '@/generated/prisma/models'
|
||||||
|
import mapConsumerWithLicenseUtil from '@/modules/consumer/utils/mapConsumerWithLicense.util'
|
||||||
import { PrismaService } from '@/prisma/prisma.service'
|
import { PrismaService } from '@/prisma/prisma.service'
|
||||||
import { BadRequestException, Injectable } from '@nestjs/common'
|
import { BadRequestException, Injectable } from '@nestjs/common'
|
||||||
import { ResponseMapper } from 'common/response/response-mapper'
|
import { ResponseMapper } from 'common/response/response-mapper'
|
||||||
@@ -45,44 +46,6 @@ export class AdminConsumersService {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly mapConsumer = (consumer: any) => {
|
|
||||||
const { activated_licenses, ...rest } = consumer
|
|
||||||
|
|
||||||
let lastLicense: any = null
|
|
||||||
|
|
||||||
if (consumer.activated_licenses.length) {
|
|
||||||
lastLicense = consumer.activated_licenses[0]
|
|
||||||
if (consumer.activated_licenses.length > 1) {
|
|
||||||
const activeLicenseInfo = consumer.activated_licenses.find(
|
|
||||||
activated_license => activated_license.expires_at,
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!activeLicenseInfo) {
|
|
||||||
consumer.activated_licenses.sort((a, b) =>
|
|
||||||
a.expires_at > b.expires_at ? 1 : -1,
|
|
||||||
)
|
|
||||||
lastLicense = consumer.activated_licenses[0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
...rest,
|
|
||||||
fullname: `${rest?.first_name} ${rest?.last_name}`,
|
|
||||||
license_info: this.prepareLicenseInfo(lastLicense),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly prepareLicenseInfo = (latestLicense: any) => {
|
|
||||||
if (!latestLicense) return null
|
|
||||||
const { license, ...rest } = latestLicense
|
|
||||||
|
|
||||||
return {
|
|
||||||
...rest,
|
|
||||||
partner: license.charged_license_transaction.partner,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async findAll() {
|
async findAll() {
|
||||||
const [consumers, count] = await this.prisma.$transaction([
|
const [consumers, count] = await this.prisma.$transaction([
|
||||||
this.prisma.consumer.findMany({
|
this.prisma.consumer.findMany({
|
||||||
@@ -91,7 +54,7 @@ export class AdminConsumersService {
|
|||||||
this.prisma.consumer.count(),
|
this.prisma.consumer.count(),
|
||||||
])
|
])
|
||||||
|
|
||||||
return ResponseMapper.paginate(consumers.map(this.mapConsumer), { count })
|
return ResponseMapper.paginate(consumers.map(mapConsumerWithLicenseUtil), { count })
|
||||||
}
|
}
|
||||||
|
|
||||||
async findOne(id: string) {
|
async findOne(id: string) {
|
||||||
@@ -100,7 +63,7 @@ export class AdminConsumersService {
|
|||||||
select: this.defaultSelect,
|
select: this.defaultSelect,
|
||||||
})
|
})
|
||||||
|
|
||||||
return ResponseMapper.single(this.mapConsumer(consumer))
|
return ResponseMapper.single(mapConsumerWithLicenseUtil(consumer))
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(data: CreateConsumerDto) {
|
async create(data: CreateConsumerDto) {
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
import { Body, Controller, Get, Param, Post } from '@nestjs/common'
|
import { multerImageOptions } from '@/multer.config'
|
||||||
import { CreateGuildGoodDto } from './dto/create-good.dto'
|
import {
|
||||||
|
Body,
|
||||||
|
Controller,
|
||||||
|
Get,
|
||||||
|
Param,
|
||||||
|
Patch,
|
||||||
|
Post,
|
||||||
|
UploadedFile,
|
||||||
|
UseInterceptors,
|
||||||
|
} from '@nestjs/common'
|
||||||
|
import { FileInterceptor } from '@nestjs/platform-express'
|
||||||
|
import { ApiBody, ApiConsumes } from '@nestjs/swagger'
|
||||||
|
import { CreateGuildGoodDto, UpdateGuildGoodDto } from './dto/create-good.dto'
|
||||||
import { GoodsService } from './goods.service'
|
import { GoodsService } from './goods.service'
|
||||||
|
|
||||||
@Controller('admin/guilds/:guildId/goods')
|
@Controller('admin/guilds/:guildId/goods')
|
||||||
@@ -17,7 +29,36 @@ export class GoodsController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
create(@Body() data: CreateGuildGoodDto) {
|
@UseInterceptors(FileInterceptor('file', multerImageOptions))
|
||||||
return this.goodsService.create(data)
|
@ApiConsumes('multipart/form-data')
|
||||||
|
@ApiBody({
|
||||||
|
schema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
image: { type: 'string', format: 'binary' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
create(@Body() data: CreateGuildGoodDto, @UploadedFile() file: Express.Multer.File) {
|
||||||
|
return this.goodsService.create(data, file)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Patch(':id')
|
||||||
|
@UseInterceptors(FileInterceptor('image', multerImageOptions))
|
||||||
|
@ApiConsumes('multipart/form-data')
|
||||||
|
@ApiBody({
|
||||||
|
schema: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
image: { type: 'string', format: 'binary' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
update(
|
||||||
|
@Param('id') id: string,
|
||||||
|
@Body() data: UpdateGuildGoodDto,
|
||||||
|
@UploadedFile() file: Express.Multer.File,
|
||||||
|
) {
|
||||||
|
return this.goodsService.update(id, data, file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { UploaderModule } from '@/modules/uploader/uploader.module'
|
||||||
import { PrismaModule } from '@/prisma/prisma.module'
|
import { PrismaModule } from '@/prisma/prisma.module'
|
||||||
import { Module } from '@nestjs/common'
|
import { Module } from '@nestjs/common'
|
||||||
import { GoodsController } from './goods.controller'
|
import { GoodsController } from './goods.controller'
|
||||||
@@ -5,7 +6,7 @@ import { GoodsService } from './goods.service'
|
|||||||
import { GuildGoodImagesModule } from './images/images.module'
|
import { GuildGoodImagesModule } from './images/images.module'
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [PrismaModule, GuildGoodImagesModule],
|
imports: [PrismaModule, GuildGoodImagesModule, UploaderModule],
|
||||||
controllers: [GoodsController],
|
controllers: [GoodsController],
|
||||||
providers: [GoodsService],
|
providers: [GoodsService],
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,39 +1,46 @@
|
|||||||
import { GoodOmit } from '@/generated/prisma/models'
|
import { UploadedFileTypes } from '@/common/enums/enums'
|
||||||
|
import { GoodSelect, GoodWhereInput } from '@/generated/prisma/models'
|
||||||
|
import { UploaderService } from '@/modules/uploader/uploader.service'
|
||||||
import { PrismaService } from '@/prisma/prisma.service'
|
import { PrismaService } from '@/prisma/prisma.service'
|
||||||
import { Injectable } from '@nestjs/common'
|
import { Injectable } from '@nestjs/common'
|
||||||
import { ResponseMapper } from 'common/response/response-mapper'
|
import { ResponseMapper } from 'common/response/response-mapper'
|
||||||
import { CreateGuildGoodDto } from './dto/create-good.dto'
|
import { CreateGuildGoodDto, UpdateGuildGoodDto } from './dto/create-good.dto'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class GoodsService {
|
export class GoodsService {
|
||||||
constructor(private prisma: PrismaService) {}
|
constructor(
|
||||||
|
private prisma: PrismaService,
|
||||||
|
private readonly uploaderService: UploaderService,
|
||||||
|
) {}
|
||||||
|
|
||||||
private readonly goodOmit = {
|
private readonly defaultSelect: GoodSelect = {
|
||||||
complex_id: true,
|
id: true,
|
||||||
barcode: true,
|
name: true,
|
||||||
base_sale_price: true,
|
pricing_model: true,
|
||||||
is_default_guild_good: true,
|
unit_type: true,
|
||||||
local_sku: true,
|
image_url: true,
|
||||||
} as GoodOmit
|
sku: true,
|
||||||
|
description: true,
|
||||||
async findAll(guildId: string) {
|
|
||||||
const [goods, count] = await this.prisma.$transaction([
|
|
||||||
this.prisma.good.findMany({
|
|
||||||
where: {
|
|
||||||
is_default_guild_good: true,
|
|
||||||
category: {
|
|
||||||
guild_id: guildId,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
include: {
|
|
||||||
category: {
|
category: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
name: true,
|
name: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly defaultWhere = (guild_id: string): GoodWhereInput => ({
|
||||||
|
is_default_guild_good: true,
|
||||||
|
category: {
|
||||||
|
guild_id,
|
||||||
},
|
},
|
||||||
omit: this.goodOmit,
|
})
|
||||||
|
|
||||||
|
async findAll(guildId: string) {
|
||||||
|
const [goods, count] = await this.prisma.$transaction([
|
||||||
|
this.prisma.good.findMany({
|
||||||
|
where: this.defaultWhere(guildId),
|
||||||
|
select: this.defaultSelect,
|
||||||
}),
|
}),
|
||||||
this.prisma.good.count(),
|
this.prisma.good.count(),
|
||||||
])
|
])
|
||||||
@@ -46,41 +53,81 @@ export class GoodsService {
|
|||||||
const good = await this.prisma.good.findUnique({
|
const good = await this.prisma.good.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id,
|
id,
|
||||||
is_default_guild_good: true,
|
...(this.defaultWhere(guild_id) as any),
|
||||||
category: {
|
|
||||||
guild_id,
|
|
||||||
},
|
},
|
||||||
},
|
select: this.defaultSelect,
|
||||||
|
|
||||||
include: {
|
|
||||||
category: {
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
name: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
omit: this.goodOmit,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return ResponseMapper.single(good)
|
return ResponseMapper.single(good)
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(data: CreateGuildGoodDto) {
|
async create(data: CreateGuildGoodDto, file: Express.Multer.File) {
|
||||||
const { category_id, ...rest } = data
|
const { category_id, ...rest } = data
|
||||||
|
|
||||||
const good = await this.prisma.good.create({
|
const good = await this.prisma.$transaction(async tx => {
|
||||||
|
let image_url = ''
|
||||||
|
if (file) {
|
||||||
|
const uploadedUrl = await this.uploaderService.uploadFile(
|
||||||
|
file,
|
||||||
|
UploadedFileTypes.GOOD,
|
||||||
|
)
|
||||||
|
image_url = uploadedUrl || ''
|
||||||
|
}
|
||||||
|
|
||||||
|
return await tx.good.create({
|
||||||
data: {
|
data: {
|
||||||
|
...rest,
|
||||||
|
is_default_guild_good: true,
|
||||||
|
image_url,
|
||||||
category: {
|
category: {
|
||||||
connect: {
|
connect: {
|
||||||
id: category_id,
|
id: category_id,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
select: this.defaultSelect,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return ResponseMapper.create(good)
|
||||||
|
}
|
||||||
|
|
||||||
|
async update(id: string, data: UpdateGuildGoodDto, file: Express.Multer.File) {
|
||||||
|
const { category_id, ...rest } = data
|
||||||
|
|
||||||
|
const good = await this.prisma.$transaction(async tx => {
|
||||||
|
let image_url = ''
|
||||||
|
if (file) {
|
||||||
|
const uploadedUrl = await this.uploaderService.uploadFile(
|
||||||
|
file,
|
||||||
|
UploadedFileTypes.GOOD,
|
||||||
|
)
|
||||||
|
image_url = uploadedUrl || ''
|
||||||
|
}
|
||||||
|
|
||||||
|
const prevImage = await tx.good.findUnique({
|
||||||
|
where: { id },
|
||||||
|
select: { image_url: true },
|
||||||
|
})
|
||||||
|
|
||||||
|
if (image_url && prevImage?.image_url) {
|
||||||
|
this.uploaderService.deleteFile(prevImage.image_url, UploadedFileTypes.GOOD)
|
||||||
|
}
|
||||||
|
|
||||||
|
return await tx.good.update({
|
||||||
|
where: { id },
|
||||||
|
data: {
|
||||||
...rest,
|
...rest,
|
||||||
is_default_guild_good: true,
|
is_default_guild_good: true,
|
||||||
|
image_url,
|
||||||
|
category: {
|
||||||
|
connect: {
|
||||||
|
id: category_id,
|
||||||
},
|
},
|
||||||
omit: this.goodOmit,
|
},
|
||||||
|
},
|
||||||
|
select: this.defaultSelect,
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
return ResponseMapper.create(good)
|
return ResponseMapper.create(good)
|
||||||
|
|||||||
@@ -23,7 +23,10 @@ export class GuildGoodImagesService {
|
|||||||
const url = await this.uploadFileService.uploadFile(file, UploadedFileTypes.GOOD)
|
const url = await this.uploadFileService.uploadFile(file, UploadedFileTypes.GOOD)
|
||||||
if (url) {
|
if (url) {
|
||||||
if (currentImage.image_url) {
|
if (currentImage.image_url) {
|
||||||
this.uploadFileService.deleteFile(currentImage.image_url)
|
this.uploadFileService.deleteFile(
|
||||||
|
currentImage.image_url,
|
||||||
|
UploadedFileTypes.GOOD,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return this.prisma.good.update({
|
return this.prisma.good.update({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { ConsumerMiddleware } from './consumer.middleware'
|
|||||||
import { ConsumerService } from './consumer.service'
|
import { ConsumerService } from './consumer.service'
|
||||||
import { ConsumerCustomersModule } from './customers/customers.module'
|
import { ConsumerCustomersModule } from './customers/customers.module'
|
||||||
import { ConsumerPosesModule } from './poses/poses.module'
|
import { ConsumerPosesModule } from './poses/poses.module'
|
||||||
|
import { ConsumerSaleInvoicesModule } from './saleInvoices/saleInvoices.module'
|
||||||
import { ConsumerStatisticsModule } from './statistics/statistics.module'
|
import { ConsumerStatisticsModule } from './statistics/statistics.module'
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
@@ -17,6 +18,7 @@ import { ConsumerStatisticsModule } from './statistics/statistics.module'
|
|||||||
ConsumerCustomersModule,
|
ConsumerCustomersModule,
|
||||||
ConsumerStatisticsModule,
|
ConsumerStatisticsModule,
|
||||||
ConsumerPosesModule,
|
ConsumerPosesModule,
|
||||||
|
ConsumerSaleInvoicesModule,
|
||||||
],
|
],
|
||||||
providers: [JwtService, ConsumerService],
|
providers: [JwtService, ConsumerService],
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { ResponseMapper } from '@/common/response/response-mapper'
|
import { ResponseMapper } from '@/common/response/response-mapper'
|
||||||
import { PrismaService } from '@/prisma/prisma.service'
|
import { PrismaService } from '@/prisma/prisma.service'
|
||||||
import { Injectable } from '@nestjs/common'
|
import { Injectable } from '@nestjs/common'
|
||||||
|
import mapConsumerWithLicenseUtil from './utils/mapConsumerWithLicense.util'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ConsumerService {
|
export class ConsumerService {
|
||||||
@@ -41,26 +42,6 @@ export class ConsumerService {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const { activated_licenses, ...rest } = consumer
|
return ResponseMapper.single(mapConsumerWithLicenseUtil(consumer))
|
||||||
|
|
||||||
const mappedData = {
|
|
||||||
...rest,
|
|
||||||
activated_licenses: activated_licenses.map(activatedLicense => {
|
|
||||||
const { license, ...rest } = activatedLicense
|
|
||||||
return {
|
|
||||||
...rest,
|
|
||||||
license: {
|
|
||||||
id: license.id,
|
|
||||||
partner: license.charged_license_transaction.partner,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
|
|
||||||
return ResponseMapper.single({
|
|
||||||
...consumer,
|
|
||||||
full_name: `${consumer?.first_name} ${consumer?.last_name}`,
|
|
||||||
activated_licenses: mappedData,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,20 @@
|
|||||||
import { TokenAccount } from '@/common/decorators/tokenInfo.decorator'
|
import { TokenAccount } from '@/common/decorators/tokenInfo.decorator'
|
||||||
import { Controller, Get } from '@nestjs/common'
|
import { Controller, Get, Param } from '@nestjs/common'
|
||||||
import { ApiTags } from '@nestjs/swagger'
|
import { ApiTags } from '@nestjs/swagger'
|
||||||
import { SaleInvoicesService } from './saleInvoices.service'
|
import { SaleInvoicesService } from './saleInvoices.service'
|
||||||
|
|
||||||
@ApiTags('ConsumerStatistics')
|
@ApiTags('ConsumerSaleInvoices')
|
||||||
@Controller('consumer/statistics')
|
@Controller('consumer/sale-invoices')
|
||||||
export class StatisticsController {
|
export class StatisticsController {
|
||||||
constructor(private readonly service: SaleInvoicesService) {}
|
constructor(private readonly service: SaleInvoicesService) {}
|
||||||
|
|
||||||
@Get('invoices')
|
@Get('')
|
||||||
async getInvoices(@TokenAccount('userId') consumerId: string) {
|
async findAll(@TokenAccount('userId') consumerId: string) {
|
||||||
return this.service.getInvoices(consumerId)
|
return this.service.findAll(consumerId)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get(':id')
|
||||||
|
async findOne(@TokenAccount('userId') consumerId: string, @Param('id') id: string) {
|
||||||
|
return this.service.findOne(consumerId, id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ export class SaleInvoicesService {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
async getInvoices(consumer_id: string, page = 1, pageSize = 10) {
|
async findAll(consumer_id: string, page = 1, pageSize = 10) {
|
||||||
const invoicesWhere: SalesInvoiceWhereInput = {
|
const invoicesWhere: SalesInvoiceWhereInput = {
|
||||||
consumer_account: {
|
consumer_account: {
|
||||||
consumer_id,
|
consumer_id,
|
||||||
@@ -82,7 +82,7 @@ export class SaleInvoicesService {
|
|||||||
return ResponseMapper.paginate(invoices, { page, pageSize, count })
|
return ResponseMapper.paginate(invoices, { page, pageSize, count })
|
||||||
}
|
}
|
||||||
|
|
||||||
async getInvoice(consumer_id: string, id: string) {
|
async findOne(consumer_id: string, id: string) {
|
||||||
const invoicesWhere: SalesInvoiceWhereUniqueInput = {
|
const invoicesWhere: SalesInvoiceWhereUniqueInput = {
|
||||||
id,
|
id,
|
||||||
consumer_account: {
|
consumer_account: {
|
||||||
@@ -95,6 +95,12 @@ export class SaleInvoicesService {
|
|||||||
...this.defaultSelect,
|
...this.defaultSelect,
|
||||||
notes: true,
|
notes: true,
|
||||||
created_at: true,
|
created_at: true,
|
||||||
|
payments: {
|
||||||
|
select: {
|
||||||
|
amount: true,
|
||||||
|
payment_method: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
items: {
|
items: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
export * from './mapConsumerWithLicense.util'
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
export default (consumer: any) => {
|
||||||
|
const { activated_licenses, ...rest } = consumer
|
||||||
|
|
||||||
|
let lastLicense: any = null
|
||||||
|
|
||||||
|
if (consumer.activated_licenses.length) {
|
||||||
|
lastLicense = consumer.activated_licenses[0]
|
||||||
|
if (consumer.activated_licenses.length > 1) {
|
||||||
|
const activeLicenseInfo = consumer.activated_licenses.find(
|
||||||
|
activated_license => activated_license.expires_at,
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!activeLicenseInfo) {
|
||||||
|
consumer.activated_licenses.sort((a, b) => (a.expires_at > b.expires_at ? 1 : -1))
|
||||||
|
lastLicense = consumer.activated_licenses[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...rest,
|
||||||
|
fullname: `${rest?.first_name} ${rest?.last_name}`,
|
||||||
|
license_info: prepareLicenseInfo(lastLicense),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function prepareLicenseInfo(latestLicense: any) {
|
||||||
|
if (!latestLicense) return null
|
||||||
|
const { license, ...rest } = latestLicense
|
||||||
|
|
||||||
|
return {
|
||||||
|
...rest,
|
||||||
|
partner: license.charged_license_transaction.partner,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,8 +18,6 @@ export class PartnerMiddleware implements NestMiddleware {
|
|||||||
|
|
||||||
async use(req: Request, _res: Response, next: NextFunction) {
|
async use(req: Request, _res: Response, next: NextFunction) {
|
||||||
const doForbidden = () => {
|
const doForbidden = () => {
|
||||||
console.log('doForbidden')
|
|
||||||
|
|
||||||
throw new ForbiddenException('شما دسترسی لازم را ندارید')
|
throw new ForbiddenException('شما دسترسی لازم را ندارید')
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ export class GoodsService {
|
|||||||
is_default_guild_good: true,
|
is_default_guild_good: true,
|
||||||
pricing_model: true,
|
pricing_model: true,
|
||||||
unit_type: true,
|
unit_type: true,
|
||||||
|
image_url: true,
|
||||||
category: {
|
category: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ export class PosController {
|
|||||||
const result = await this.service.getInfo(pos_id)
|
const result = await this.service.getInfo(pos_id)
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
console.log('first')
|
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
res.cookie('posId', pos_id, {
|
res.cookie('posId', pos_id, {
|
||||||
httpOnly: false,
|
httpOnly: false,
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ export class StorageService {
|
|||||||
return publicUrl
|
return publicUrl
|
||||||
})
|
})
|
||||||
.catch(ex => {
|
.catch(ex => {
|
||||||
console.log(ex)
|
|
||||||
throw ex
|
throw ex
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -46,7 +45,7 @@ export class StorageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async deleteFile(key: string) {
|
async deleteFile(key: string) {
|
||||||
await this.s3.send(
|
return await this.s3.send(
|
||||||
new DeleteObjectCommand({
|
new DeleteObjectCommand({
|
||||||
Bucket: this.bucket,
|
Bucket: this.bucket,
|
||||||
Key: key,
|
Key: key,
|
||||||
|
|||||||
@@ -9,25 +9,14 @@ export class UploaderService {
|
|||||||
async uploadFile(file: Express.Multer.File, type: UploadedFileTypes) {
|
async uploadFile(file: Express.Multer.File, type: UploadedFileTypes) {
|
||||||
const uploaded = await this.storageService.uploadFile(file, type)
|
const uploaded = await this.storageService.uploadFile(file, type)
|
||||||
return uploaded
|
return uploaded
|
||||||
|
|
||||||
// await fs.mkdir(dirPath, { recursive: true })
|
|
||||||
// await fs.writeFile(filePath, buffer)
|
|
||||||
|
|
||||||
// Return a URL path, e.g. /uploads/{accountId}/{type}/{filename}
|
|
||||||
// return `/uploads/${type}/${filename}`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteFile(url: string) {
|
async deleteFile(url: string, type: UploadedFileTypes) {
|
||||||
const key = url?.split('/').pop()
|
const key = `${type}/${url?.split('/').pop()}`
|
||||||
|
|
||||||
if (key) {
|
if (key) {
|
||||||
return await this.storageService.deleteFile(key)
|
return await this.storageService.deleteFile(key)
|
||||||
}
|
}
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
// await fs.mkdir(dirPath, { recursive: true })
|
|
||||||
// await fs.writeFile(filePath, buffer)
|
|
||||||
|
|
||||||
// Return a URL path, e.g. /uploads/{accountId}/{type}/{filename}
|
|
||||||
// return `/uploads/${type}/${filename}`
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user