Skip to content

Commit

Permalink
fix: improve note date filtering and clean up PWA configuration #376
Browse files Browse the repository at this point in the history
- Updated PWA configuration to conditionally disable service worker in development mode for better debugging.
- Refactored note date filtering logic to combine start and end date checks into a single condition, enhancing clarity and performance.
- Cleaned up code formatting for better readability in note attachment handling.
  • Loading branch information
blinko-space committed Dec 26, 2024
1 parent c3890e7 commit 5e2cf71
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const withPWA = require('next-pwa')({
dest: 'public',
register: true,
skipWaiting: true,
disable: false, // process.env.NODE_ENV === 'development',
disable: process.env.NODE_ENV === 'development', // process.env.NODE_ENV === 'development',
fallbacks: {
document: '/offline'
},
Expand Down
37 changes: 17 additions & 20 deletions src/server/routers/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,8 @@ export const noteRouter = router({
if (withoutTag) {
where.tags = { none: {} }
}
if (startDate) {
where.createdAt = { gte: startDate }
}
if (endDate) {
where.createdAt = { lte: endDate }
if (startDate && endDate) {
where.createdAt = { gte: startDate, lte: endDate }
}
if (withLink) {
where.OR = [
Expand Down Expand Up @@ -393,17 +390,17 @@ export const noteRouter = router({
if (needTobeAddedAttachmentsPath.length != 0) {
await prisma.attachments.createMany({
data: attachments?.filter(t => needTobeAddedAttachmentsPath.includes(t.path))
.map(i => {
.map(i => {
const pathParts = (i.path as string)
.replace('/api/file/', '')
.replace('/api/s3file/', '')
.split('/');
return {
noteId: note.id,
return {
noteId: note.id,
...i,
depth: pathParts.length - 1,
perfixPath: pathParts.slice(0, -1).join(',')
}
}
})
})
}
Expand All @@ -414,30 +411,30 @@ export const noteRouter = router({
return note
} else {
try {
const note = await prisma.notes.create({
data: {
content: content ?? '',
type,
accountId: Number(ctx.id),
isShare: isShare ? true : false,
const note = await prisma.notes.create({
data: {
content: content ?? '',
type,
accountId: Number(ctx.id),
isShare: isShare ? true : false,
isTop: isTop ? true : false,
...(input.createdAt && { createdAt: input.createdAt }),
...(input.updatedAt && { updatedAt: input.updatedAt })
}
}
})
await handleAddTags(tagTree, undefined, note.id)
await prisma.attachments.createMany({
data: attachments.map(i => {
data: attachments.map(i => {
const pathParts = (i.path as string)
.replace('/api/file/', '')
.replace('/api/s3file/', '')
.split('/');
return {
noteId: note.id,
return {
noteId: note.id,
...i,
depth: pathParts.length - 1,
perfixPath: pathParts.slice(0, -1).join(',')
}
}
})
})

Expand Down

0 comments on commit 5e2cf71

Please sign in to comment.